[fpc-pascal] Managed record questions
Ryan Joseph
ryan at thealchemistguild.com
Fri Mar 9 10:29:43 CET 2018
> On Mar 9, 2018, at 4:13 PM, Ryan Joseph <ryan at thealchemistguild.com> wrote:
>
> type
> TDataObject = object
> v: array[0..2] of integer;
> end;
>
> procedure TestObjectCopy;
> var
> obj: TDataObject;
> data: array[0..2] of integer;
> i: integer;
> begin
> for i := 0 to 2 do
> obj.v[i] := 100 + (100 * i);
>
> Move(obj, data, sizeof(TDataObject));
> for i := 0 to 2 do
> writeln(data[i]);
> end;
Actually this doesn’t work. VMT table breaks the data.
Program below returns:
10
20
30
32766
0
0
with the virtual method and:
10
20
30
100
200
300
without the virtual method.
type
TSuperDataObject = object
a: array[0..2] of integer;
procedure Test; virtual; abstract;
end;
type
TDataObject = object (TSuperDataObject)
b: array[0..2] of integer;
procedure Test;
end;
procedure TDataObject.Test;
begin
end;
procedure TestObjectCopy;
var
obj: TDataObject;
data: array[0..5] of integer;
i: integer;
begin
for i := 0 to 2 do
begin
obj.a[i] := 10 + (10 * i);
obj.b[i] := 100 + (100 * i);
end;
Move(obj, data, sizeof(TDataObject));
for i := 0 to 5 do
writeln(data[i]);
end;
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list