Thank you Jürgen,That is just a example but Its good to know there is now way. Thank you Sven for examples.I didn't know about advanced record support.
Regards, Ara On Tue, Mar 10, 2015, at 11:43 PM, Sven Barth wrote: > On 10.03.2015 22:23, aradeonas wrote: > > Hi, > > How can I compare two record? > > Like this : > > > > type > > TRec=record > > na:string; > > end; > > > > var > > R1,R2:TRec; > > Begin > > R1.na:='A'; > > R2.na:='B'; > > if R1<>R2 then > > Showmessage('Error') > > At the declaration of TRec add this: > > === code begin === > > operator = (aLeft, aRight: TRec): Boolean; > > === code end === > > and then implement it like this: > > === code begin === > > operator = (aLeft, aRight: TRec): Boolean; > begin > Result := aLeft.na = aRight.na; > end; > > === code end === > > Alternatively you can declare the operator inside TRec if you enable > modeswitch advancedrecords: > > === code begin === > type > TRec = record > na: String; > class operator = (aLeft, aRight: TRec): Boolean; > end; > > === code end === > > Implementation: > > === code begin === > > class operator TRec.=(aLeft, aRight: TRec): Boolean; > begin > Result := aLeft,na = aRight.na; > end; > > === code end === > > This /should/ work though I did not test it by compilation. > > Regards, > Sven > > -- > _______________________________________________ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- http://www.fastmail.com - Choose from over 50 domains or use your own -- _______________________________________________ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus