Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread Martin Wynne via fpc-pascal
On 12/09/2022 15:37, James Richters via fpc-pascal wrote: So I could just do this? Index:= MyStringlist.IndexOfName(SearchName); If Index >=0 then MyValue := MyStringlist[Index].ValueFromIndex; Hi James, I would probably do try with MyStringList do

Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread James Richters via fpc-pascal
So I could just do this? Index:= MyStringlist.IndexOfName(SearchName); If Index >=0 then MyValue := MyStringlist[Index].ValueFromIndex; That sure is nice to know, Thank you! I guess for my dynamic arrays of records, I still need to search with a loop... or is there a cool thing I don't

Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread Martin Wynne via fpc-pascal
On 12/09/2022 14:16, James Richters via fpc-pascal wrote: The problem with the for in loop is that I need the index. Hi James, You don't need a loop for that: index:=MyStringlist.IndexOfName; see: https://www.freepascal.org/docs-html/rtl/classes/tstrings.indexofname.html martin.

Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread James Richters via fpc-pascal
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

Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread Peter B via fpc-pascal
On 12/09/2022 07:52, Jean SUZINEAU via fpc-pascal wrote: As Bart suggested, you can use too the for/in loop:  for s in sl do WriteLn( s); And that is IMHO by far the most elegant, and least error prone, representation. Cheers, Peter ___ fpc-pascal

Re: [fpc-pascal] Get highest element of a StringList

2022-09-12 Thread Jean SUZINEAU via fpc-pascal
As Bart suggested, you can use too the for/in loop:  for s in sl do WriteLn( s); For example: var    sl: TStringList;    s: String; begin sl:= TStringList.Create; try     sl.Add('1');     sl.Add('2');     for s in sl do WriteLn( s); finally     FreeAndNil(

Re: [fpc-pascal] Get highest element of a StringList

2022-09-11 Thread James Richters via fpc-pascal
The loops is just an example because in my original post of why I wanted to get the highest element of a stringlist was because I wanted a for loop that wasn't as clumsy as For I:=0 to myStringlist.count-1 Do This came up because thanks to this discussion list, I learned I could use High() and

Re: [fpc-pascal] Get highest element of a StringList

2022-09-11 Thread Sven Barth via fpc-pascal
James Richters via fpc-pascal schrieb am Sa., 10. Sep. 2022, 22:55: > > For some reason > {$Mode FPC} > {$modeswitch typehelpers} > Still had Error: Identifier not found "class" > Because support for the "class" keyword is only available when the modeswitch Class is enabled which is the case

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Travis Siegel via fpc-pascal
o: 'FPC-Pascal users discussions' Sent: Saturday, September 10, 2022, 19:57:51 Subject: [fpc-pascal] Get highest element of a StringList This Helper sounds like a nice way to do it. I need the numerical index of the loop so this would be more straight forward. Would I then do someth

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Martin Wynne via fpc-pascal
On 10/09/2022 17:01, James Richters via fpc-pascal wrote: For Loop := 0 to MyStringList.Count-1 do It would be nice to not have the -1 I don't understand what is wrong with Count-1, but you can get the highest index like this if you wish:

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread James Richters via fpc-pascal
Thank you for the example! I also needed {$Mode OBJFPC} to get it working. I am normally in {$Mode FPC} Or {$Mode TP} But I found that if I just put this in a unit that is {$Mode OBJFPC} and include that unit in my {$Mode TP} Unit it works just great! I have a useless unit that is just a

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Thomas Kurz via fpc-pascal
o: 'FPC-Pascal users discussions' Sent: Saturday, September 10, 2022, 19:57:51 Subject: [fpc-pascal] Get highest element of a StringList This Helper sounds like a nice way to do it. I need the numerical index of the loop so this would be more straight forward. Would I then do someth

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Thomas Kurz via fpc-pascal
: Saturday, September 10, 2022, 19:57:51 Subject: [fpc-pascal] Get highest element of a StringList This Helper sounds like a nice way to do it. I need the numerical index of the loop so this would be more straight forward. Would I then do something like : For I:= 0 to MyStringList.High Do ? When I

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread James Richters via fpc-pascal
This Helper sounds like a nice way to do it. I need the numerical index of the loop so this would be more straight forward. Would I then do something like : For I:= 0 to MyStringList.High Do ? When I try to add the Type statement: type TStringListHelper = class helper for TStringList function

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Thomas Kurz via fpc-pascal
users discussions' Sent: Saturday, September 10, 2022, 18:01:20 Subject: [fpc-pascal] Get highest element of a StringList I thought I would try: For Loop := 0 to High(MyStringList) do But I get "Error: Type mismatch" Is there a way to get the highest element of a stringlist

Re: [fpc-pascal] Get highest element of a StringList

2022-09-10 Thread Bart via fpc-pascal
On Sat, Sep 10, 2022 at 6:01 PM James Richters via fpc-pascal wrote: > Is there a way to get the highest element of a stringlist other than: > > For Loop := 0 to MyStringList.Count-1 do You can use the for .. in loop. > It would be nice to not have the -1 > Could High() be made to work if the

[fpc-pascal] Get highest element of a StringList

2022-09-10 Thread James Richters via fpc-pascal
I thought I would try: For Loop := 0 to High(MyStringList) do But I get "Error: Type mismatch" Is there a way to get the highest element of a stringlist other than: For Loop := 0 to MyStringList.Count-1 do It would be nice to not have the -1 Could High() be made to work if the argument was a