Setting the name of a control created at runtime lazarus / 31-LCL ---------------------------------------------------------------------- vfclists · 2014-06-24 14:54 When I create a control at run time and set the parent, an error is raised if the parent contains a control with the same name. Is there an option to  code to give a control a sequential name similar how the IDE does it at design time? Is it possible for controls to have the same name so long as they have different parents? ---------------------------------------------------------------------- wp · 2014-06-24 15:15 I normally leave the name of run-time created controls empty. If I need them I call them directly by their variable name instead of seeking them based on their "name" property. ---------------------------------------------------------------------- taazz · 2014-06-24 15:18 no parents have nothing to do with the name use only owners do. Why do you need to name a runtime created control in the first place the name is used by the streaming mechanism and that is the reason it has to be unique. Leaving the name empty should allow you to have multiple of those controls with out a problem. I any case there is the file ideCommands of ideintf package which has the TIDECommandScopes class with the method CreateUniqueName. Take a look on how it is implemented I guess you would need to duplicate it in your own code. ---------------------------------------------------------------------- vfclists · 2014-06-25 14:09 The object in question is actually a frame. I think Frames are different controls and I remember reading somewhere that they need customized constructors in some cases. Do you know of some documentation which covers this topic and how overriding the constructor can help in the case? Quote from: taazz on June 24, 2014, 05:18:47 pmno parents have nothing to do with the name use only owners do. Why do you need to name a runtime created control in the first place the name is used by the streaming mechanism and that is the reason it has to be unique. Leaving the name empty should allow you to have multiple of those controls with out a problem. I any case there is the file ideCommands of ideintf package which has the TIDECommandScopes class with the method CreateUniqueName. Take a look on how it is implemented I guess you would need to duplicate it in your own code. ---------------------------------------------------------------------- taazz · 2014-06-25 14:59 Quote from: vfclists on June 25, 2014, 04:09:26 pmThe object in question is actually a frame. I think Frames are different controls and I remember reading somewhere that they need customized constructors in some cases. Do you know of some documentation which covers this topic and how overriding the constructor can help in the case? No sorry I don't remember any frame specific documentation and I do not understand what the constructor could do in this case that a simple procedure can't accomplish. In any case just leave it empty I do it all the time in my dynamically created frames with no problems so far. ---------------------------------------------------------------------- jdlinke · 2014-06-25 19:39 Much like others have posted here, this is how I have approached this problem. I'm using an array of frames, but you can do the same thing when making several independent frames at runtime. Code: [Select]unit formUnitMain; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,   types, ExtCtrls, Buttons, ComCtrls, unitTypeTile; type   { TformMain }   TformMain = class(TForm)     ScrollBox1: TScrollBox;     procedure FormCreate(Sender: TObject);   private     { private declarations }   public     { public declarations }     FrameTypeTile : array of TframeTypeTile; // My frames   end; var   formMain: TformMain; implementation {$R *.lfm} { TformMain } procedure TformMain.FormCreate(Sender: TObject); var   i : Integer;   fileList : TStringList; begin   // I do some processing here to get a list of files (fileList) for my particular application   SetLength(FrameTypeTile, 1); // FrameTypeTile is the frame I designed   for i := fileList.Count-1 downto 0 do // Use downto so my frames are in the right order when using align:=alTop   begin     SetLength(FrameTypeTile, Length(FrameTypeTile)+1);         FrameTypeTile[i] := TframeTypeTile.Create(formMain); // Who owns the frame(s)     FrameTypeTile[i].Name := ''; // Blank works just fine!     FrameTypeTile[i].Parent := ScrollBox1; // Where the frame will be placed     FrameTypeTile[i].Align := alTop;   end; end; end. Hope it helps. ---------------------------------------------------------------------- vfclists · 2014-06-26 10:53 Quote from: vfclists on June 25, 2014, 04:09:26 pmThe object in question is actually a frame. I think Frames are different controls and I remember reading somewhere that they need customized constructors in some cases. Do you know of some documentation which covers this topic and how overriding the constructor can help in the case? It turned out to be much easier than I suspected. It was a simple matter of overriding the constructor and setting the Name='' Code: [Select]constructor TFrame01.Create(AOwner: TComponent); begin   inherited Create(AOwner);   Name := ''; end; ---------------------------------------------------------------------- jdlinke · 2014-06-26 13:07 QuoteIt was a simple matter of overriding the constructor and setting the Name='' Nice. That's a bit more elegant than setting the name in the main program as each instance of the frame is created as I was doing