ddablib / envvars

Environment Variables Unit
1 stars 2 forks source link

Add new `TList<>` and `TDictionary<>` overloads of `TPJEnvironmentVars.GetAll` #16

Closed delphidabbler closed 2 years ago

delphidabbler commented 2 years ago

The TPJEnvironmentVars.GetAll methods return both TStrings and TArray<TPJEnvironmentVar> types.

I'm suggesting the following additional overloads:

delphidabbler commented 2 years ago

On second thoughts I'm not inclined to add these methods because it's so easy to implement creating these data structures in user code.

For example, if GetAll(const List: TList<TPJEnvironmentVar> was implemented the code to use it would look something like:

var L := Tlist<TPJEnvironmentVar>.Create( { ... } ):
TPJEnvironmentVars.GetAll(L);
{ Do something with L }
L.Free;

Using existing enumerators we achieve the same thing with:

var L := Tlist<TPJEnvironmentVar>.Create( { ... } ):
TPJEnvironmentVars.EnumVars<Integer>(
  procedure (const EnvVar: TPJEnvironmentVar; Data: Integer)
  begin
    L.Add(EnvVar);
  end,
  0
);
{ Do something with L }
L.Free;

Not too much extra code, I think. And omitting the GetAll overrides keeps the TPJEnvironmentVars class a bit cleaner.

delphidabbler commented 2 years ago

Not too much extra code, I think. And omitting the GetAll overrides keeps the TPJEnvironmentVars class a bit cleaner.

And if the proposed new enumerator overloads in issue #17 come to pass, things will be simplified a little by avoiding any parameterisation of the enumerator methods and not needing the dummy Data parameter.

delphidabbler commented 2 years ago

Decided against adding these methods.