How to insert a form in a unit and have the IDE manage it? lazarus / 10-Designer ---------------------------------------------------------------------- jamie · 2024-10-15 19:57 I have question about later deciding to insert a Form in a UNIT that got started without any interacting with the IDE designer. Is it possible to insert a form class into an existing unit and have it be managed by the IDE/OI ? I don't mean in forms of editing the LFM file, is there an option to start a new form within an existing unit? ---------------------------------------------------------------------- MarkMLl · 2024-10-15 20:22 What happens if you add the relevant .pas file to the project? I admit to being somewhat uncomfortable with this distinction between "form" and "unit", which is something that I've seen people making repeatedly (https://forum.lazarus.freepascal.org/index.php/topic,65825.0.html and so on). The important thing is the unit and the class (descendant of TForm) defined therein in the context of Object Pascal: the IDE should take note of the presence of that and (a) compile the associated .lfm into a collection of resources and (b) use those resources to populate a form at program startup. MarkMLl ---------------------------------------------------------------------- jamie · 2024-10-15 20:54 That's just it, I don't have a Form already in the process, I have a unit that I would like to have a visiual editable form in it now. I just put in TMYFORM = Class(TFORM) ... etc. I don't have any options for INSERT a form instead of starting a new form which starts a new empty unit with the form. Also, I would like to know if creating Frames can be held to the current project and not installed on the IDE bar? ---------------------------------------------------------------------- MarkMLl · 2024-10-15 21:24 Quote from: jamie on October 15, 2024, 10:54:03 pmThat's just it, I don't have a Form already in the process, I have a unit that I would like to have a visiual editable form in it now. I don't have any options for INSERT a form instead of starting a new form which starts a new empty unit with the form. Tell the IDE to open the .pas file and then make sure it's added to the project. If that doesn't work then I suspect we need Martin, as the IDE guru, in here. QuoteAlso, I would like to know if creating Frames can be held to the current project and not installed on the IDE bar? A frame is entirely in the local project. It's just a control instantiated onto the current form, and isn't in some way added to the IDE. (Noting the repeated warnings against trying to edit a frame after it's been instantiated, which invariably ends badly.) MarkMLl ---------------------------------------------------------------------- jamie · 2024-10-15 22:11 I need to make a ToolBar type controls and the main form is getting large where these toolbars are going to be used. So I want to make each toolbar type control in different forms because these toolbars are also basically like a form with no caption border etc., they have properties and methods etc.   I have no intention of dropping them on the form at design time, these will be created and parented to the control housing the toolbars. these bars will also perform floating and docking operations.  Current project I am converting over has many of these that are more than just the toolbar control, they have all sorts of fields that are relevant only to the project, they need to be created at startup and keep that way, regardless of how they are being accessed visually.  Thank you. ---------------------------------------------------------------------- Sieben · 2024-10-15 23:12 Maybe you're looking for sth like this - from my own version but essentially code from unit Dialogs. Creating a TForm code only: 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 type   { TaxInputForm }   TaxInputForm = class(TForm)  private    Edit: TCustomEdit;    FNonChars: TCharSet;    procedure InputEditChange(Sender: TObject);    procedure InputEditKeyPress(Sender: TObject; var Key: Char);  protected    procedure Activate; override;  end; // + the implementations  function axCreateInputDialog(OwnerForm: TCustomForm;                           const ACaption, APrompt: string;                             MaskInput: Boolean; NonChars: TCharSet;                             const AMask: string; AEditClass: TEditClass;                           var Value: string): TaxInputForm;var Prompt: TLabel;    MinEditWidth: integer;    AMonitor: TMonitor;begin  Result := nil;  Result := TaxInputForm(TaxInputForm.NewInstance);  Result.DisableAutoSizing;  Result.CreateNew(OwnerForm);  with Result do  begin    FNonChars := NonChars;    PopupMode := pmAuto;    BorderStyle := bsDialog;    Caption := ACaption;    Prompt := TLabel.Create(Result);    with Prompt do    begin      Parent := Result;      Caption := APrompt;      Align := alTop;      AutoSize := True;    end;    Edit := AEditClass.Create(Result);    with Edit do  begin      Parent := Result;      Top := Prompt.Height;      Align := alTop;      BorderSpacing.Top := 3;      AMonitor := _InputQueryActiveMonitor;      // check that edit is smaller than our monitor, it must be smaller at least      // by 6 * 2 pixels (spacing from window borders) + window border      MinEditWidth := Min(AMonitor.Width - 20,                      Max(cInputQueryEditSizePixels,                      AMonitor.Width * cInputQueryEditSizePercents div 100));      Constraints.MinWidth := MinEditWidth;      OnKeyPress := @Result.InputEditKeyPress;      OnChange := @Result.InputEditChange;      {$ifdef with_picedits}      if (AEditClass = TPxPicEdit) then        TPxPicEdit(Edit).ValueConstraints.PictureMask := AMask;      {$endif}      if (AEditClass = TMaskEdit) then        TMaskEdit(Edit).EditMask := AMask;      if (Value > '') then Text := Value;      TabStop := True;      if MaskInput then      begin        EchoMode := emPassword;        PasswordChar := '*';      end else      begin      EchoMode := emNormal;        PasswordChar := #0;      end;      TabOrder := 0;    end;     with TaxDlgBtnPnl.Create(Result) do    begin      Top := Edit.Top + Edit.Height;      Parent := Result;      ShowBevel := False;      ShowButtons := [pbOK, pbCancel];      Align := alTop;    end;     ChildSizing.TopBottomSpacing := 6;    ChildSizing.LeftRightSpacing := 6;    AutoSize := True;     InputEditChange(Edit);     // upon show, the edit control will be focused for editing, because it's    // the first in the tab order    Result.EnableAutoSizing;  end;end;   IDE/OI, however, will of course not manage this. ---------------------------------------------------------------------- LV · 2024-10-16 14:28 Quote from: jamie on October 15, 2024, 09:57:39 pm  I have question about later deciding to insert a Form in a UNIT that got started without any interacting with the IDE designer. Is it possible to insert a form class into an existing unit and have it be managed by the IDE/OI ? I don't mean in forms of editing the LFM file, is there an option to start a new form within an existing unit? The answer is yes if the conditions are met: 1) the *.lfm file must be created, otherwise the Object Inspector will not see the form; 2) You need to add a line to the *.lpr (Application.CreateForm(...); I spent 3 mins checking it out. Quote from: MarkMLl on October 15, 2024, 10:22:39 pmWhat happens if you add the relevant .pas file to the project? I admit to being somewhat uncomfortable with this distinction between "form" and "unit", which is something that I've seen people making repeatedly (https://forum.lazarus.freepascal.org/index.php/topic,65825.0.html and so on). The important thing is the unit and the class (descendant of TForm) defined therein in the context of Object Pascal: the IDE should take note of the presence of that and (a) compile the associated .lfm into a collection of resources and (b) use those resources to populate a form at program startup. MarkMLl I'm of the same opinion. I will add a discussion close to this issue https://forum.lazarus.freepascal.org/index.php/topic,68574.0.html