Skip to content

Commit

Permalink
Call management initialize operator for records inside classes (recor…
Browse files Browse the repository at this point in the history
…d with management operators as field) (rtl/inc/objpas.inc, TObject.InitInstance)
  • Loading branch information
maciej-izak committed Nov 21, 2016
1 parent 9baa32a commit 5043b4b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rtl/inc/objpas.inc
Expand Up @@ -379,6 +379,11 @@

class function TObject.InitInstance(instance : pointer) : tobject; {$ifdef SYSTEMINLINE} inline; {$ENDIF}

{$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
var
vmt : PVmt;
temp : pointer;
{$endif FPC_HAS_MANAGEMENT_OPERATORS}
begin
{ the size is saved at offset 0 }
fillchar(instance^, InstanceSize, 0);
Expand All @@ -387,6 +392,21 @@
ppointer(instance)^:=pointer(self);
if {$ifdef VER3_0}PVmt(self)^.vIntfTable <> @emptyintf{$else}assigned(PVmt(self)^.vIntfTable){$endif} then
InitInterfacePointers(self,instance);

{$ifdef FPC_HAS_MANAGEMENT_OPERATORS}
{ for management operators like initialize call int_initialize }
vmt := PVmt(self);
while vmt<>nil do
begin
Temp:= vmt^.vInitTable;
{ The RTTI format matches one for records, except the type is tkClass.
Since RecordRTTI does not check the type, calling it yields the desired result. }
if Assigned(Temp) then
RecordRTTI(Instance,Temp,@int_initialize);
vmt:= vmt^.vParent;
end;
{$endif FPC_HAS_MANAGEMENT_OPERATORS}

InitInstance:=TObject(Instance);
end;

Expand Down

0 comments on commit 5043b4b

Please sign in to comment.