diff --git a/ide/customformeditor.pp b/ide/customformeditor.pp index e2935ccb32..453f8a5f51 100644 --- a/ide/customformeditor.pp +++ b/ide/customformeditor.pp @@ -246,10 +246,13 @@ each control that's dropped onto the form function CreateChildComponentFromStream(BinStream: TStream; ComponentClass: TComponentClass; Root: TComponent; ParentControl: TWinControl): TIComponentInterface; override; + procedure WriterFindAncestor(Writer: TWriter; Component: TComponent; + const Name: string; + var Ancestor, RootAncestor: TComponent); procedure SetComponentNameAndClass(CI: TIComponentInterface; - const NewName, NewClassName: shortstring); + const NewName, NewClassName: shortstring); function GetDescendantTypeClass(TypeClass: TComponentClass): TComponentClass; - + // ancestors function GetAncestorLookupRoot(AComponent: TComponent): TComponent; override; function GetAncestorInstance(AComponent: TComponent): TComponent; override; @@ -1355,11 +1358,8 @@ begin try BinCompStream.Position:=0; Writer:=CreateLRSWriter(BinCompStream,DestroyDriver); - AncestorUnitInfo:=AnUnitInfo.FindAncestorUnit; - Ancestor:=nil; - if AncestorUnitInfo<>nil then - Ancestor:=AncestorUnitInfo.Component; - Writer.WriteDescendent(AnUnitInfo.Component,Ancestor); + Writer.OnFindAncestor:=@WriterFindAncestor; + Writer.WriteDescendent(AnUnitInfo.Component,nil); if DestroyDriver then Writer.Driver.Free; FreeAndNil(Writer); AnUnitInfo.ComponentLastBinStreamSize:=BinCompStream.Size; @@ -1728,6 +1728,30 @@ begin Result:=CreateComponentInterface(NewComponent,true); end; +procedure TCustomFormEditor.WriterFindAncestor(Writer: TWriter; + Component: TComponent; const Name: string; var Ancestor, + RootAncestor: TComponent); +// Note: TWriter wants the stream ancestor, which is not always the class ancestor +var + AnUnitInfo: TUnitInfo; +begin + //DebugLn(['TCustomFormEditor.WriterFindAncestor START ',DbgSName(Component)]); + AnUnitInfo:=Project1.UnitWithComponentClass(TComponentClass(Component.ClassType)); + if (AnUnitInfo<>nil) then begin + if (AnUnitInfo.Component=Component) then begin + // Component is a root component (e.g. not nested, inline) + // the stream ancestor is the component of the ClassParent + AnUnitInfo:=AnUnitInfo.FindAncestorUnit; + end else begin + // Component is a nested, inline component + // the stream ancestor is the component of the class + end; + if (AnUnitInfo<>nil) and (AnUnitInfo.Component<>nil) then + Ancestor:=AnUnitInfo.Component; + DebugLn(['TCustomFormEditor.WriterFindAncestor Component=',DbgSName(Component),' Ancestor=',DbgSName(Ancestor)]); + end; +end; + procedure TCustomFormEditor.SetComponentNameAndClass(CI: TIComponentInterface; const NewName, NewClassName: shortstring); var diff --git a/ide/main.pp b/ide/main.pp index 30d4cf2495..6c368fab7e 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -4648,8 +4648,6 @@ var CompResourceCode, LFMFilename, TestFilename, ResTestFilename: string; UnitSaveFilename: String; ADesigner: TDesigner; - AncestorUnit: TUnitInfo; - AncestorInstance: TComponent; Grubber: TLRTGrubber; LRTFilename: String; begin @@ -4699,13 +4697,9 @@ begin {$IFNDEF DisableFakeMethods} Writer.OnWriteMethodProperty:=@FormEditor1.WriteMethodPropertyEvent; {$ENDIF} - AncestorUnit:=GetAncestorUnit(AnUnitInfo); - if AncestorUnit<>nil then - AncestorInstance:=AncestorUnit.Component - else - AncestorInstance:=nil; //DebugLn(['TMainIDE.DoSaveUnitComponent AncestorInstance=',dbgsName(AncestorInstance)]); - Writer.WriteDescendent(AnUnitInfo.Component,AncestorInstance); + Writer.OnFindAncestor:=@FormEditor1.WriterFindAncestor; + Writer.WriteDescendent(AnUnitInfo.Component,nil); if DestroyDriver then Writer.Driver.Free; FreeAndNil(Writer); AnUnitInfo.ComponentLastBinStreamSize:=BinCompStream.Size;