[fpc-devel] Object upgrades

Ryan Joseph genericptr at gmail.com
Mon Jun 10 21:31:01 CEST 2019



> On Jun 10, 2019, at 3:25 PM, Ben Grasset <operator97 at gmail.com> wrote:
> 
> Result in your example is the size of a pointer in all cases, which is fine / exactly what you'd expect it to be.
> 

Sorry, if I dereference the size is still of TBase. I don’t think “result" is actually changing depending on the class type. This may have something to do with the way new works though. How can we fix this? 

type
  PBase = ^TBase;
  TBase = object
    constructor Initialize;
    class function Create: PBase; static;
  end;

class function TBase.Create: PBase;
begin
  new(result, Initialize);
  writeln('create: ', sizeof(result^));
end;

constructor TBase.Initialize;
begin
  writeln('create tfoo')
end;

type
  PChild = ^TChild;
  TChild = object (TBase)
    y: string;
  end;

var
  c: PChild;
begin
  c := PChild(TChild.Create);


Regards,
	Ryan Joseph




More information about the fpc-devel mailing list