ddablib / envvars

Environment Variables Unit
1 stars 2 forks source link

Add enumerator overloads with no Data parameter. #17

Open delphidabbler opened 2 years ago

delphidabbler commented 2 years ago

Although the Data parameter of the various TPJEnvironmentVars enumerator methods is useful on occasion, a lot of the time it isn't required.

So how about a couple more enumerator overloads without the Data parameter? E.g.:

TPJEnvironmentVars = class(TObject)
// ...
public 
  // ...
  type
    TEnumNamesCallback = reference to procedure (const VarName: string);
    TEnumVarsCallback = reference to procedure(const EnvVar: TPJEnvironmentVar);
    //.. 
  class procedure EnumNames(Callback: TEnumNamesCallback); overload;
  class procedure EnumVars(Callback: TEnumVarsCallback); overload;
  // ...
end;

// ...

class procedure TPJEnvironmentVars.EnumNames(Callback: TEnumNamesCallback)
begin
  Assert(Assigned(Callback));
  EnumNames<Integer>(
    procedure (const VarName: string; Data: Integer)
    begin
      Callback(VarName);
    end,
    0 // Dummy value
  );
end;

class procedure TPJEnvironmentVars.EnumVars(Callback: TEnumVarsCallback)
begin
  Assert(Assigned(Callback));
  EnumVars<Integer>(
    procedure (const EnvVar: TPJEnvironmentVar; Data: Integer)
    begin
      Callback(EnvVar);
    end,
    0 // Dummy value
  );
end;