[fpc-pascal] TFPObjectlist example

James Richters james at productionautomation.net
Tue Sep 8 20:07:00 CEST 2020


What’s the difference between TList and TFPGList?  Which one is better for this example?
 
James
 
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of Vojtech Cihák via fpc-pascal
Sent: Tuesday, September 8, 2020 10:29 AM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Cc: Vojtěch Čihák <vojtech.cihak at atlas.cz>
Subject: Re: [fpc-pascal] TFPObjectlist example
 
Hi,
 
some crippled formatting, so again:
 
However, in your case (records) I would rather use TFPGList from FGL unit:
 
1) add {$modeswitch ADVANCEDRECORDS}
 
2) add FGL to uses
 
3) define class operator =
 
test = record
    Port :String;
    Size :Byte;
    Status :Word;
    class operator = (A,B: test): Boolean;
  End; 
4) implement it
class 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: "Vojtěch Čihák via fpc-pascal" <fpc-pascal at lists.freepascal.org <mailto:fpc-pascal at lists.freepascal.org> >
> Komu: james at productionautomation.net <mailto:james at productionautomation.net> , "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org <mailto:fpc-pascal at lists.freepascal.org> >
> Datum: 08.09.2020 16:21
> Předmět: Re: [fpc-pascal] TFPObjectlist example
>
______________________________________________________________
> Od: "James Richters via fpc-pascal" <fpc-pascal at lists.freepascal.org <mailto:fpc-pascal at lists.freepascal.org> >
> Komu: "'FPC-Pascal users discussions'" <fpc-pascal at lists.freepascal.org <mailto: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 <mailto:fpc-pascal at lists.freepascal.org> 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


----------

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org <mailto:fpc-pascal at lists.freepascal.org> 
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/0ed27676/attachment-0001.htm>


More information about the fpc-pascal mailing list