Container for non-visual components ? lazarus / 31-LCL ---------------------------------------------------------------------- FrankBKK · 2021-06-24 12:46 What is the best approach to place non-visual components on a Form to avoid clutter and constant re-arranging ? I tried to put them in a DataModule  but that created a bunch of other problems for some components. ---------------------------------------------------------------------- lucamar · 2021-06-24 13:24 For a relatively small number of them (say, open/save/print dialogs, main/popup menus, action list, and little else) what I do is to place a "discardable" panel aligned some convenient place and put the components over it. Then I either hide or destroy the panel on startup. Maybe not the best solution but it works quite well most of the times if using a DataModule gives you problems. ---------------------------------------------------------------------- Zvoni · 2021-06-24 13:50 If (and that's a very big "if") i use something like that (e.g. the Database-Trinity - Connection, Transaction, Query) i actually resize my Form to "big", and put those components "out of the way" after i have set up everything in the Object Inspector. Then i size the Form back to the size i want. Done ---------------------------------------------------------------------- wp · 2021-06-24 13:59 With nonvisual components on a TDataModule it is important that the datamodule is created BEFORE the form which uses them. Go to the project options, section "Forms", and move the datamodule to the top of the "Auto-create forms". I do this regularly with imagelists shared between several forms. See also the lpr project file: 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 begin  RequireDerivedFormResource:=True;  Application.Title:='project1';  Application.Scaled:=True;  Application.Initialize;  Application.CreateForm(TDataModule1, DataModule1);  // <--- Must be BEFORE Form1  Application.CreateForm(TForm1, Form1);  Application.Run;end. You can turn off non-visual components altogether by unchecking the option "Show nonvisual components" in the form's context menu. Then you can find the non-visual components only in the object tree above the object inspector. In many cases I populate most properties of the nonvisual components at runtime. In this case it does not make much sense to put them on the form at designtime at all. Create them at runtime - it's only a single line: 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   SaveDialog1 := TSaveDialog.Create(self);In this context it is a good trick to temporarily drop the component on the form and delete it immediately afterwards - this adds the required unit(s) to the uses clause. ---------------------------------------------------------------------- FrankBKK · 2021-06-24 16:03 Quote from: wp on June 24, 2021, 03:59:39 pmWith nonvisual components on a TDataModule it is important that the datamodule is created BEFORE the form which uses them. That is part of my problem - I have some non-visual components that refer to components on the main form (e.g. LazReport for StringGrids) so I run into a chcken-egg problem.  Quote from: wp on June 24, 2021, 03:59:39 pmIn many cases I populate most properties of the nonvisual components at runtime. In this case it does not make much sense to put them on the form at designtime at all. Create them at runtime - it's only a single line: Agreed - I think that's the way to go ... Thanks for your help ! ---------------------------------------------------------------------- Remy Lebeau · 2021-06-25 01:44 Quote from: FrankBKK on June 24, 2021, 06:03:18 pmThat is part of my problem - I have some non-visual components that refer to components on the main form (e.g. LazReport for StringGrids) so I run into a chcken-egg problem.  You could simply use multiple DataModules. Place any non-visual controls that the Form requires into a DataModule that is created before the Form is created. Place any non-visual controls that require the Form into another DataModule that is created after the Form is created. ---------------------------------------------------------------------- egsuh · 2021-06-25 01:59 WOW I found several approaches here. QuoteIn this context it is a good trick to temporarily drop the component on the form and delete it immediately afterwards - this adds the required unit(s) to the uses clause. I drop a component on a form, then I move the definitions of non- visual components from published to private (or public) section, then I delete component from the form. This leaves declarations of the classes. QuotePlace any non-visual controls that the Form requires into a DataModule that is created before the Form is created. If the non-visual controls in the datamodule are used only by the form, then datamodule may be created within form creation by manual code. QuoteYou can turn off non-visual components altogether by unchecking the option "Show nonvisual components" in the form's context menu. I did not know this. Learning a lot everyday.