[fpc-pascal] Get highest element of a StringList

James Richters james.richters at productionautomation.net
Sat Sep 10 22:55:06 CEST 2022


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 whole list of constants, types, and
variables used by my other units, just so I don't have to scroll past over
1000 lines of code just to get to the functions and procedures.
It was {$Mode FPC}

For some reason
{$Mode FPC}
{$modeswitch typehelpers}
Still had Error: Identifier not found "class"

So I changed it to 
{$Mode OBJFPC}
{$modeswitch typehelpers}
And put the function in it, and it's working great!

My main reason for wanting something like this is because I occasionally
will forget the -1 and... well... that's no good...
Since I recently learned of High() and Low() for arrays, I've been changing
all my for loops with arrays to use High() and sometimes Low() if they don't
start at 0.  It's also helpful to do something like:

MyArray[High(MyArray)] := something;  

To write to a newly added array element where I used to have

MyArray[Length(MyArray)-1] := something;  

While it does work.. it's less readable and prone to errors.

James



More information about the fpc-pascal mailing list