delphi – Get id from Values in a StringList

delphi – Get id from Values in a StringList

Example is from the Delphi Basics, but TStringList.Names is also described in the Delphi documentation

  // Now display all name and age pair values
  for i := 0 to names.Count-1 do
  begin
    ShowMessage(names.Names[i]+ is +names.ValueFromIndex[i]);
  end;

You can use the TALNVStringList (NV for nameValue) from alcinoe (https://github.com/Zeus64/alcinoe) to handle Name and Value without all the time splitting the string

TALNVStringList is exactly the same as TStringList (nothing to change in the code except replacing TstringList by TALNVStringList) except that its more efficient in speed because its store the name in one dedicated field and the value in another dedicated field (no need to do all the time pos(=) and copy() to retrieve the name and the value of the row)

  for i := 0 to aOldPriceTerms.Count-1 do
  begin
    ShowMessage(aOldPriceTerms.Names[i]+ is +aOldPriceTerms.ValueFromIndex[i]);
  end;

Exe demo showing the speed penalty of classic TstringList: https://svn.code.sf.net/p/alcinoe/code/demos/ALSortedListBenchmark/win32/ALSortedListBenchmark.exe

delphi – Get id from Values in a StringList

To get all the ids

for name in names.Names do
begin
  i := names.IndexOf[name];
end;

or

To get all the Values

for name in vOldTermsList.Names do
begin
   Value := vOldTermsList.Value[name];
end;

Leave a Reply

Your email address will not be published. Required fields are marked *