How to overload assign operator for record in Delphi -


i want make type of record uses dynamic arrays.

using variables , b of type want able perform operations a: = b (and other) , able modify content of without modification b in snipped code below:

    type       tmyrec = record         inner_array: array of double;       public         procedure setsize(n: integer);         class operator implicit(source: tmyrec): tmyrec;       end;      implementation      procedure tmyrec.setsize(n: integer);     begin       setlength(inner_array, n);     end;      class operator tmyrec.implicit(source: tmyrec): tmyrec;     begin     //here want copy data source destination (a b in simple example below)     //but here compilator error     //[dcc error] : e2521 operator 'implicit' must take 1 'tmyrec' type in parameter or result type     end;       var       a, b: tmyrec;     begin       a.setsize(2);       a.inner_array[1] := 1;       b := a;       a.inner_array[1] := 0; //here same values inside , b (they pointed same inner memory) 

there 2 problems:

  1. when don't use overriding assigning operator in tmyrec, a:=b means , b (their inner_array) pointing same place in memory.
  2. to avoid problem 1) want overload assign operator using:

    class operator tmyrec.implicit(source: tmyrec): tmyrec;

but compilator (delphi xe) says:

[dcc error] : e2521 operator 'implicit' must take 1 'tmyrec' type in parameter or result type

how resolve problems. read several similar posts on stackoverflow don't work (if understood well) on situation.

artik

it not possible overload assignment operator. means attempting not possible.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -