[fpc-pascal] Is it always safe to typecast a old style object as its parent?

Dennis dec12 at avidsoft.com.hk
Tue Aug 1 14:52:25 CEST 2017



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.



More information about the fpc-pascal mailing list