[SOLVED] TIniPropStorage: how to add an array to my INI-file? lazarus / 31-LCL ---------------------------------------------------------------------- Hartmut · 2017-01-26 14:55 My program uses a TIniPropStorage to save some data in an INI-file. This works fine for objects which are created by the object inspector and for "normal" variables like integers, but not for an array of TColorBoxes. My code looks like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IniPropStorage, ColorBox; type ColorBoxArray = array of TColorBox; { TForm1 }  TForm1 = class(TForm)  ColorBox1: TColorBox;  IniPropStorage1: TIniPropStorage;  procedure FormCreate(Sender: TObject); private   CB: ColorBoxArray;   FField1: Integer; public published   property CBA: ColorBoxArray read CB write CB;   property Field1: Integer read FField1 write FField1; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);   var i: integer;   begin   Field1:=55;   SetLength(CB,3); // is 20 in my real program   for i:=0 to High(CBA) do      begin      CBA[i]:=TColorBox.Create(self);      CBA[i].Top:=10;      CBA[i].Left:=i*120;      CBA[i].Parent:=self;      end;   Form1.SessionProperties:='Top;Left;ColorBox1.Selected;'     + 'CBA[1].Selected;CBA[2].Selected;CBA[3].Selected;Field1;'   end; end.  It compiles and shows no runtime error, but my INI-file contains only: Code: [Select][TApplication.Form1] Form1_Top=344 Form1_Left=329 ColorBox1_Selected=32768 Form1_Field1=55 So it works for ColorBox1 (created by the object inspector) and for Field1 (integer variable), but not for array CBA[]. Can please somebody tell me what I am doing wrong? I attached a small demo project. Thanks in advance. I use FPC 3.0.0 with Lazarus 1.6.2 on Windows 7. ---------------------------------------------------------------------- Leledumbo · 2017-01-26 16:39 AFAIK TWhateverPropStorage relies on streaming, in which dynamically created components don't count. You will have to do saving and loading manually, using provided On(Save|Restore)ingProperties and (Read|Write)(Integer|String|Boolean|Rect|Strings), setting IniSection if you want. ---------------------------------------------------------------------- Hartmut · 2017-01-26 17:07 Quote from: Leledumbo on January 26, 2017, 05:39:04 pmAFAIK TWhateverPropStorage relies on streaming, in which dynamically created components don't count. If the dynamic array is the problem, I would prefer to use a normal array, but I cannot compile this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, IniPropStorage, ColorBox; type ColorBoxArray = array[1..3] of TColorBox; // is 20 in my real program { TForm1 }  TForm1 = class(TForm)  ColorBox1: TColorBox;  IniPropStorage1: TIniPropStorage;  procedure FormCreate(Sender: TObject); private   CB: ColorBoxArray;   FField1: Integer; public published   property CBA: ColorBoxArray read CB write CB;   property Field1: Integer read FField1 write FField1; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);   var i: integer;   begin   Field1:=55;   for i:=0 to High(CBA) do      begin      CBA[i]:=TColorBox.Create(self);      CBA[i].Top:=10;      CBA[i].Left:=i*120;      CBA[i].Parent:=self;      end;   Form1.SessionProperties:='Top;Left;ColorBox1.Selected;'     + 'CBA[1].Selected;CBA[2].Selected;CBA[3].Selected;Field1;'   end; end. I get an Error "This kind of property cannot be published" in line 24 (this error was the only reason why I switched to a dynamic array). Does somebody have an idea how to compile with a normal array? ---------------------------------------------------------------------- Leledumbo · 2017-01-27 04:54 Quote from: Hartmut on January 26, 2017, 06:07:56 pmIf the dynamic array is the problem, I would prefer to use a normal array, but I cannot compile this: No, I said streaming, not dynamic array. Meaning the property you want to save/restore automatically must reside within the designed form, it cannot be anything you generate at runtime in memory. You can't escape from doing it manually. Quote from: Hartmut on January 26, 2017, 06:07:56 pmI get an Error "This kind of property cannot be published" in line 24 (this error was the only reason why I switched to a dynamic array). Does somebody have an idea how to compile with a normal array? Static arrays, especially the one you created, cannot be published. As documented, its size is bigger than a pointer. ---------------------------------------------------------------------- Hartmut · 2017-01-27 15:13 Thanks a lot to Leledumbo for your help and the documentation link. Now I know why my static array didn't compile. Here are the 2 recommended events which work fine: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.IniPropStorage1SavingProperties(Sender: TObject);   var i: integer;   begin   for i:=0 to High(CBA) do      IniPropStorage1.WriteInteger('CBA_' + IntToStr(i), CBA[i].Selected);   end; procedure TForm1.IniPropStorage1RestoringProperties(Sender: TObject);   var i: integer;   begin   for i:=0 to High(CBA) do      CBA[i].Selected:=IniPropStorage1.ReadInteger('CBA_' + IntToStr(i),0);   end; After this my INI-file contains array CBA[] too: Code: [Select][TApplication.Form1] CBA_0=65280 CBA_1=65535 CBA_2=255 Form1_Top=344 Form1_Left=329 ColorBox1_Selected=16711680 Form1_Field1=55