From 231b2c42bf09e8220fafe33f4ad45a17bd32cc5a Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 30 Dec 2013 09:33:09 +0000 Subject: [PATCH] Import / export GraphicContainer --- Packages/X2CLGraphicsEditor.dfm | 2 +- Packages/X2CLGraphicsEditor.pas | 35 ++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Packages/X2CLGraphicsEditor.dfm b/Packages/X2CLGraphicsEditor.dfm index 90b675c..c0b70fa 100644 --- a/Packages/X2CLGraphicsEditor.dfm +++ b/Packages/X2CLGraphicsEditor.dfm @@ -201,7 +201,7 @@ object GraphicsEditorForm: TGraphicsEditorForm Left = 20 Top = 360 Bitmap = { - 494C010107000900040010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 + 494C010107000900080010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600 0000000000003600000028000000400000002000000001002000000000000020 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 diff --git a/Packages/X2CLGraphicsEditor.pas b/Packages/X2CLGraphicsEditor.pas index 62da487..0d36a68 100644 --- a/Packages/X2CLGraphicsEditor.pas +++ b/Packages/X2CLGraphicsEditor.pas @@ -466,6 +466,7 @@ var index: Integer; graphic: TX2GraphicContainerItem; fileName: string; + startIndex: Integer; begin if dlgImport.Execute then @@ -476,8 +477,21 @@ begin exit; end; + { Items inherited from the ancestor through visual inheritance can not + be deleted. Start at the first one introduced at this level. } + startIndex := 0; + while (startIndex < FComponent.GraphicCount) and (csAncestor in FComponent.Graphics[startIndex].ComponentState) do + Inc(startIndex); + lstGraphics.Clear; - FComponent.Clear; + + if startIndex = 0 then + FComponent.Clear + else + begin + for index := Pred(FComponent.GraphicCount) downto startIndex do + FComponent.Graphics[index].Free; + end; importPath := ExtractFilePath(dlgImport.FileName); importFile := TIniFile.Create(dlgImport.FileName); @@ -486,16 +500,19 @@ begin while importFile.ValueExists('PictureName', IntToStr(index)) do begin - graphic := TX2GraphicContainerItem(FComponentDesigner.CreateComponent(TX2GraphicContainerItem, nil, 0, 0, 0, 0)); - - if Assigned(graphic) then + if index >= startIndex then begin - graphic.Container := FComponent; - graphic.PictureName := importFile.ReadString('PictureName', IntToStr(index), IntToStr(index)); + graphic := TX2GraphicContainerItem(FComponentDesigner.CreateComponent(TX2GraphicContainerItem, nil, 0, 0, 0, 0)); - fileName := importFile.ReadString('FileName', IntToStr(index), ''); - if (Length(fileName) > 0) and FileExists(importPath + fileName) then - graphic.Picture.LoadFromFile(importPath + fileName); + if Assigned(graphic) then + begin + graphic.Container := FComponent; + graphic.PictureName := importFile.ReadString('PictureName', IntToStr(index), IntToStr(index)); + + fileName := importFile.ReadString('FileName', IntToStr(index), ''); + if (Length(fileName) > 0) and FileExists(importPath + fileName) then + graphic.Picture.LoadFromFile(importPath + fileName); + end; end; Inc(index);