[fpc-pascal] Get highest element of a StringList

James Richters james.richters at productionautomation.net
Mon Sep 12 15:16:59 CEST 2022


The problem with the for in loop is that I need the index.

I'm sometimes searching through the stringlist looking for a match, and when I find a match, I want to read the value
And then do a break, because there is no point is searching once I found what I am looking for:

For I:= 0 to MyStringlist.high Do
   Begin
       If MyStringlist[I].Names = SearchName Then
          Begin
                MyValue := MyStringlist[I].ValueFromIndex;
                Break;
          End;
   End;

I agree that the for - in loop is a great way if you are always processing the entire list and don't need the index for anything.

James



More information about the fpc-pascal mailing list