ddablib / envvars

Environment Variables Unit
1 stars 2 forks source link

Add comparison operators to TPJEnvironmentVar #21

Open delphidabbler opened 2 years ago

delphidabbler commented 2 years ago

It could be useful to be able to compare TPJEnvironmentVar records.

Need to decide how to compare. Do we consider two records to be equal if their names are the same or if both name and value are the same.

Tests need to be case insensitive because Windows considers environment variable names to be the same if they differ only in the case of the letters.

delphidabbler commented 2 years ago

After some thought I think that we should compare the whole environment variable, name & value since it makes intuitive sense that Foo=42 and Foo=56 are not equal. But there is still a need, when checking if an environment variable is in a list for eg, to check for equal names.

So I'm thinking there should be two comparator static class methods:

  1. TPJEnvironmentVar.Compare(const A, B: TPJEnvironmentVar): Integer; that compares all fields.
  2. TPJEnvironmentVar.CompareNames(const A, B: TPJEnvironmentVar): Integer; that compares just the names.

Both have prototypes suitable for passing to a TDelegatedComparer<TPJEnvironmentVar> constructor for use with TList<> objects, for eg.

If comparison operator overloads are to be used then they should be defined in terms of TPJEnvironmentVar.Compare.

delphidabbler commented 2 years ago

Thinking of using TPJEnvironmentVar with generic collections, hash methods and, to a lesser extent, equality comparers, could be useful.