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 MyValue:=ValueFromIndex[IndexOfN
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 kn
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.
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 MyStringl
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 m
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( sl)
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 Lo
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 for
--- Original Message -
From: James Richters via fpc-pascal
To: '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
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:
high_index:=Length(Trim(MyStringList.Text))-Length(
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 who
sage -
From: James Richters via fpc-pascal
To: '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 th
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 something like :
For I
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 Hi
ascal 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 stringl
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
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 s
17 matches
Mail list logo