Browse Source

* Call management initialize operator for records inside classes (record with management operators as field) (rtl/inc/objpas.inc, TObject.InitInstance)

git-svn-id: trunk@35449 -
maciej-izak 8 years ago
parent
commit
5a7d4eb25f
1 changed files with 20 additions and 0 deletions
  1. 20 0
      rtl/inc/objpas.inc

+ 20 - 0
rtl/inc/objpas.inc

@@ -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);
@@ -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;