ddablib / envvars

Environment Variables Unit
1 stars 2 forks source link

Make TPJEnvironmentVar record read only / invariant. #9

Open delphidabbler opened 2 years ago

delphidabbler commented 2 years ago

There's no need for the user to change any fields of TPJEnvironmentVar, so we can make the record invariant by hiding the fields, adding read only properties and providing a constructor:

TPJEnvironmentVar = record
strict private
  var
    fName: string;
    fValue: string;
public
  constructor Create(const AName, AValue: string);
  ///  <summary>Environment variable name.</summary>
  property Name: string read fName;
  ///  <summary>Environment variable value.</summary>
  property Value: string read fValue;
end;

The constructor will have have the obvious simple implementation.

Wherever the records fields are directly set in the code the constructor will need to be called instead.