A suggestion..... lazarus / 8-Other ---------------------------------------------------------------------- SlackBrane · 2008-12-20 17:53 Unless there is an 'accepted' place to ask general coding questions that may not be specifically related to Lazarus/FreePascal and its development..., tell me if there is. Would it be worth having one? Something like 'General Coding Help'  ? I could be wrong but it looks like people sort of take a guess where to ask that sort of thing and the questions get smeared out across the forums. While I'm here and asking in what might be the wrong place.... I have this thing... Code: [Select]Type TMyEdit        = class(TEdit)   procedure    EditClick(Sender: TObject);   Public   Number:      Integer;   Item:        Array [0..10]of String;   Value:       Array [0..10]of String; end; TMyLabel       = class(TLabel)   procedure    LabelClick(Sender: TObject);   Public   Number:      Integer;   Item:        Array [0..5]of String;   Value:       Array [0..5]of String; end; TMyScrollBar   = class(TScrollBar)   procedure    ScrollClick(Sender: TObject);   Public   Number:      Integer;   Item:        Array [0..10]of String;   Value:       Array [0..10]of String; end; TMyPanelRecord    = Record   EditArray:   Array of TMyEdit;   LabelArray:  Array of TMyLabel;   ScrollArray: Array of TMyScrollBar; end; var MyPanelRecord: TMyPanelRecord; Which I am using to, hopefully, let the user(me) have a simplified way to create/edit the layout of a bunch of controls which are stored in the arrays within MyPanelRecord and displayed on a Panel. That Panel is going to be a common focus for setting up design parameters in the overall scheme of the program. For example in the case of TMyEdit adding another TEdit... uses this Code: [Select]procedure CreateEdit(); var PanelWidth:  Integer; begin   PanelWidth  := PanelForm.Panel1.Width;   With MyPanelRecord do   begin     SetLength(EditArray,Length(EditArray)+1);     EditArray[Length(EditArray)-1] := TMyEdit.Create(Nil);     With EditArray[Length(EditArray)-1] do     begin       Parent       := PanelForm.Panel1;       Visible      := False;       Number       := Length(EditArray);       CurrentEdit  := Number;       Item[0]      := 'LocalName';    Value[0]  := 'Edit'+IntToStr(Length(EditArray));       Item[1]      := 'Text';         Value[1]  := Value[0];       Item[2]      := 'PercentLeft';  Value[2]  := '0';       Item[3]      := 'PercentWidth'; Value[3]  := '100';       Item[4]      := 'Padding';      Value[4]  := '2';       Item[5]      := 'EditTop';      Value[5]  := '1';       Item[6]      := 'DataType';     Value[6]  := 'Integer';       Item[7]      := 'Minimum';      Value[7]  := '0';       Item[8]      := 'Maximum';      Value[8]  := '255';       Item[9]      := 'Filter';       Value[9]  := '0-9';       Item[10]     := 'Linkage';      Value[10] := '';       Left         := StrToInt(Value[4])+PanelWidth*StrToInt(Value[2])div 100;       Width        := PanelWidth*StrToInt(Value[3]) div 100-2*StrToInt(Value[4]);       Top          := StrToInt(Value[5]);       Height       := 16;       Hint         := 'Local Name '                       +Value[0];       ShowHint     := True;       Text         := Value[1];       Visible      := True;       OnClick      := EditClick;       StringGridCreate.CreateStringGrid(Item,Value);     end;   end; end;  Once the Panel layout has been designed, along with code to tie stuff up, I'd like to write the design/layout record to a file which I'll be able to read back in later for use with the other parts of the program. I hope that does not sound too mad, stupid or broken. However I would not be surprised to discover there is a 'better' way of doing this. What I am trying to avoid is having to have use the 'full' IDE to design multiple Panel Layouts and have them living in the main compiled program when I could just drag them in as required. You might guess I am not a proper programmer..... Anyway.... Things, as they are, appear to work up to a point. I can create new controls, move them about on Panel1 and set up default values by operating on the items held in the arrays within MyPanelRecord. Then things fall over, I am surprised, when I do something like trying to set the length of one of the arrays to zero which, I would assume (wrongly), would 'free' the components held in the associated array and they would disappear from Panel1.... which they don't. The other one is when I try another silly like this... Code: [Select]procedure TPanelForm.ToolButton7Click(Sender: TObject); var MyPanelFile:   File of TMyPanelRecord; FName:         String; begin   FName := '/root/paselcad/paneltest.dat';   If FileExists(FName) then   else   begin     AssignFile(MyPanelFile,FName);     ReWrite(MyPanelFile);     Write(MyPanelFile,MyPanelRecord);     CloseFile(MyPanelFile);   end; end; and, ignoring my naughty playing as root, end up with paneltest.dat being 12 bytes big irrespective of how many controls I have added to the arrays in MyPanelRecord. I sort of realise that I might be asking the compiler to do something where it does something else different to what my warped mind was looking for in the first place so it is my fault. At the moment my best guess is that MyPanelRecord just ends up as a bunch of pointers to where the real 'data' is so that is what I am operating on rather than the 'real' stuff. Any ideas? Keith ---------------------------------------------------------------------- SlackBrane · 2008-12-20 18:20 Oh, and whilst I'm on the Cider..... how about having a 'Coding Hints' section with a bunch of threads specific to certain controls. I suppose someone experienced would have to check if they are right and maybe move the useful stuff up to 'stickies' but... Coding Hints -TStringGrid --Create/Free My contribution to that one would be... Code: [Select]Procedure CreateStringGrid(Item,Value: Array of String); var Count:  Byte; begin   If PanelForm.Panel2.ContainsControl(MyStringGrid) then   begin     MyStringGrid.Options := MyStringGrid.Options -                             MyStringGrid.Options;     MyStringGrid.Free;   end;   MyStringGrid:= TMyStringGrid.Create(nil); - - - - - end; There might be better ways but this gets called and then populated by various other bits and pieces so I want to throw away the 'old' one and start again. If I try to free the control without subtracting the options from the options so there are no options then when I try and create a 'new' one I get an access violation. I'm guessing that there are some 'hooks' in Options which do not get freed by free so when you try and have a new one it finds the old ones and falls over. I'm sure I will be leaking memory all over the shop... Still, it works. There you go, probably not a bug.... definitely not a formal bug report. It is a workaround though. Keith