* * *

Author Topic: operator overloading and TFPGList with objects  (Read 1073 times)

soerensen3

  • Full Member
  • ***
  • Posts: 152
operator overloading and TFPGList with objects
« on: January 03, 2018, 01:19:47 am »
I'm having issues using objects or records together with fpc List.
When I try to specialize a list it gives me an error (without source position) that the = operator for the record/object is not overloaded. So far, so good, even if I cannot find the line where it uses the = operator for my type in the body of TFPGList.

But even if I overload the operator it is still not working:
To compile just add the unit to the uses section of an empty program.
Code: Pascal  [Select]
  1. Unit Unit1;
  2. interface
  3.  
  4. uses
  5.   fgl;
  6.  
  7. type
  8.   { TVec2 }
  9.  
  10.   TVec2 = object
  11.   end;
  12.  
  13. operator = ( A, B: TVec2 ): Boolean; //declare operator before specialization
  14.  
  15. type //start a new type section after operator declaration
  16.   TVec2List = specialize TFPGList < TVec2 >;
  17.  
  18.  
  19. implementation
  20.  
  21. operator = ( A, B: TVec2 ): Boolean;
  22. begin
  23.   Result:= True;
  24. end;
  25.  
  26. end.
  27.  

It can be done with records with a modeswitch and a class operator. For objects it does not work though:
http://forum.lazarus.freepascal.org/index.php/topic,36469.msg243242.html#msg243242

Is it possible to use TFGPList with objects? (I need inheritance)
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Blaazen

  • Hero Member
  • *****
  • Posts: 2634
  • POKE 54296,15
    • Eye-Candy Controls
Re: operator overloading and TFPGList with objects
« Reply #1 on: January 03, 2018, 01:42:31 am »
See https://forum.lazarus.freepascal.org/index.php?topic=38887.0

Note that you will have to switch from object to record. Also, I don't know if the directive {$MODESWITCH ADVANCEDRECORDS} is available in 3.0.2. Maybe you should upgrade to 3.0.4 or use SVN.
Lazarus 2.1.0 r59317M FPC 3.3.1 r39660 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.1, Plasma 5.13.5
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.14

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

soerensen3

  • Full Member
  • ***
  • Posts: 152
Re: operator overloading and TFPGList with objects
« Reply #2 on: January 03, 2018, 01:26:44 pm »
Thank you Blaazen!

I knew of the modeswitch (see the link in my post) but my question was if it was possible with objects as well, because I wanted inheritance.
But now I thought I might as well be using record helpers.

Oh and I use 3.0.4 already. The problem with the signature is you always forget updating it :)
« Last Edit: January 03, 2018, 01:55:17 pm by soerensen3 »
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus