Forum > General

[Solved]Impossible to overload assignment of equal type: How to fix that?

<< < (3/3)

jamie:

--- Quote from: Coldzer0 on July 14, 2024, 06:00:20 am ---
--- Quote from: TRon on July 14, 2024, 05:48:55 am ---
--- Quote from: Coldzer0 on July 14, 2024, 05:30:13 am ---You can do it using operator Copy

--- End quote ---
Hmz nice find.

afaik only mentioned on the new features pages and the wiki as I was unable to locate it in the documentation.

--- End quote ---

I found it here https://wiki.freepascal.org/management_operators#Copy

--- End quote ---

Yes, that works. Thank you much!

While I was there at that page, I am also interested in the initializers and finalizers, those too, will also come in handy.
 :o

PascalDragon:

--- Quote from: jamie on July 13, 2024, 08:46:33 pm ---Is there a switch that I don't know about?

--- End quote ---

No. Operators that are implemented by the compiler are not allowed to be overloaded to avoid potential confusion especially when global and scoped operators are mixed. As others wrote, use the Copy management operator for that as that correctly hooks into the copy mechanism of the RTL.

jamie:
I was scoping around my Delphi and noticed they call it "Assign" not copy.

Trying to sync source codes with a few compiler processors to keep them happy on both ends.

Thanks.

Thaddy:
Delphi did not have management operators until very recently. Freepascal has it for quite some time. That is the same as that Freepascal had generics way before Delphi.
It is thus quite common for us to see that they did not copy our syntax.
In due time, there probably will be a Delphi syntax compatible mode in {$mode delphi}. That is as usual.

Thaddy:
Unless you mean the normal assign for classes.
The advantage of the management operator copy is that it allows the programmer to implement it as a deep copy, a shallow copy, or like in your case, a partial copy, while maintaining the use of the assignment operator to perform that automatically.

Navigation

[0] Message Index

[*] Previous page

Go to full version