Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-08

Is it always safe to typecast a old style object as its parent?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dennis
TParent = object
    A : integer;
end;
TChild=object(TParent)
    B : integer;
end;
var
    Parent : TParent;
    Child : TChild;
  begin
     Child.A := 10;
     Child.B := 20;
     Parent := TParent(Child );//  is this always safe ? Will it copy

ONLY the 'A' field to 'parent'? Will it overwrite some memory space beyond the legitimate boundary of 'parent'?

end.

Thanks a lot in advance.