[fpc-pascal] TFPObjectlist example

Vojtěch Čihák vojtech.cihak at atlas.cz
Tue Sep 8 16:13:10 CEST 2020


Hi,
 
I used TFPObjectList only once, for visual component TECAccordion (https://wiki.lazarus.freepascal.org/Eye-Candy_Controls#TECAccordion). Each item of list is derived from TWinControl so it is possible to use it even for visual components (like TCollection).
 
However, in your case (records) I would rather use TFPGList from FGL unit:
 
1) add {$modeswitch ADVANCEDRECORDS}
2) add FGL to uses3) define class operator =test = record    Port :String;    Size :Byte;    Status :Word;    class operator = (A,B: test): Boolean;  End; 4) implement itclass operator test.=(A, B: test): Boolean;begin  Result:=(A.Port=B.Port) and (A.Size=B.Size);  // and ...end;   5) define specialized list:
  TMyL = specialize TFPGList<test>;
6) create it
  MyList: TMyL;
  ...
  MyList:=TMyL.Create;
 
Now you can work with it comfortably
MyList[1].Port:='abc';
 
V.
______________________________________________________________
> Od: "James Richters via fpc-pascal" <fpc-pascal at lists.freepascal.org>
> Komu: "'FPC-Pascal users discussions'" <fpc-pascal at lists.freepascal.org>
> Datum: 07.09.2020 01:08
> Předmět: [fpc-pascal] TFPObjectlist example
>

 James
 
 _______________________________________________
 fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
 https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200908/dfb2be3b/attachment.htm>


More information about the fpc-pascal mailing list