[fpc-pascal] TFPObjectlist example
Sven Barth
pascaldragon at googlemail.com
Tue Sep 8 23:23:27 CEST 2020
James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Di., 8. Sep. 2020, 20:07:
> What’s the difference between TList and TFPGList? Which one is better
> for this example?
>
The main difference is that TFPGList ist a generic, thus when you
specialize it with your record you'll have a typesafe object where you
don't need to manually work with pointers while for TList you either need
to work with pointers or declare a descendant with typesafe setters/getters
like you had done in the other mail.
You could also take a look at the generic TList in Generics.Collections
which does not require an = operator like TFPGList does.
Please note that if you work with TFPGList or the Generics.Collection.TList
then you need to modify an entry using a local variable if your entries are
records:
entry := mylist[i];
entry.field := entry.field * 2;
mylist[i] := entry;
This is because the getter for the Items property will provide a /copy/ of
the entry.
With Classes.TList you'd use a pointer however and thus you can modify it
in place.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200908/34a3cde1/attachment.htm>
More information about the fpc-pascal
mailing list