Forum > General
[Solved]Impossible to overload assignment of equal type: How to fix that?
Coldzer0:
You can do it using the operator Copy.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- TMyRecord = Record X,Y:Integer; SomeotherFields:Integer; //That I don't want to copy. class operator Copy(constref src: TMyRecord; var dst: TMyRecord); End; class operator TMyRecord.Copy(constref src: TMyRecord; var dst: TMyRecord); begin dst.X := src.X; dst.Y := src.Y; end; var a, b: TMyRecord;Begin a.X := 1; a.Y := 2; a.SomeotherFields := 3; b.X := 4; b.Y := 5; b.SomeotherFields := 6; a := b; WriteLn(Format('a.X : %d | a.Y : %d | a.SomeotherFields : %d', [a.X, a.Y, a.SomeotherFields])); // will print "a.X : 4 | a.Y : 5 | a.SomeotherFields : 3"end.
TRon:
--- 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.
Coldzer0:
--- 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
TRon:
--- Quote from: Coldzer0 on July 14, 2024, 06:00:20 am ---I found it here https://wiki.freepascal.org/management_operators#Copy
--- End quote ---
Yeah I found it there as well but unfortunately only after you posted your example because I wasn't aware that management operators existed (and they seem to exist for quite some time) so before that example was posted I had no idea what to look for :)
I can blame that on myself for not looking close enough at the new features page (3.2.0) which links to that page but quite honestly I expected it to be mentioned somewhere in the official documentation (where I was unable to find anything on management operators but perhaps I overlooked).
Than you for bringing the example to my/our attention.
Thaddy:
Unfortunaly the wiki entry is the only thing that comes close to official, although I suspect it is in the trunk/main documentation. But there are already many examples on this forum.
Navigation
[0] Message Index
[#] Next page
[*] Previous page