Trouble with TFrames lazarus / 31-LCL ---------------------------------------------------------------------- andyH · 2021-02-17 15:01 I've got an application where the main form has four tabs and about a dozen objects (labels, buttons, checklistboxes) on each tab. At the moment all the objects are defined in the constructor on the main form. I'm trying to 'improve' the code structure by moving the objects into Tframes, one for each tab with their code in the corresponding units. I've successfully created a Tframe via file > new > frame, dropped objects, e.g. a checklistbox onto the form designer and got it to work. I was able to create a constructor TFrame1.Create and modify the properties of the checklistbox, e.g. change dimensions, borders, add an item, and in the constructor for the main form: 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   myframe:= TFrame1.create(self);  myframe.Parent:= PageCtrl.page[0];was enough to get it to display = first image (is there any way to show attached images 'inline'?). But it's not what I want to do, I can't add new objects to the frame in code (doesn't update the lfm file) and I want to do it all in code (think the term is resourceless) as I have for all the other objects/forms in the application. Looked at https://wiki.freepascal.org/Frames, but it only seems to tell half the story. First attempt, I created a new unit with the following code: 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 Unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, StdCtrls, CheckLst; type  Tbaseframe = class(TForm)    Box1: TCheckListBox;    mybutton : Tbutton;   end; implementation end.//with code in the constructor for the main form  myframe:= TBaseFrame.create(self);  myframe.Parent:= PageCtrl.page[0];That resulted in a 'EResNotFound' error - Form resource Tbaseframe not found. For resourceless forms CreateNew constructor must be used. See the global variable RequireDerivedFormResource. See second image. So I changed RequireDerivedFormResource:=false from true and created a constructor in unit2: 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 Unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, StdCtrls, CheckLst; type  Tbaseframe = class(TForm)    Box1: TCheckListBox;    mybutton : Tbutton;  private  public    constructor CreateNew(TheOwner: TComponent);  end; implementation//{$R *.lfm} constructor Tbaseframe.CreateNew(TheOwner: TComponent);begin  inherited CreateNew(TheOwner);  Box1:= TCheckListBox.create(self);  box1.height:= 100;  box1.width:= 100;  Box1.show;  mybutton:= Tbutton.create(self);  mybutton.caption:= 'hello';end;end.//main form constructor:  myframe:= TBaseFrame.createnew(self);  myframe.Parent:= PageCtrl.page[0];It compiles, it runs, but it does not display the button or checkbox. See third image. I feel I'm making a newbie mistake (I am), but have been going round in circles on this for a couple of days and getting nowhere? Nothing I've tried will make the objects in the frame display. ---------------------------------------------------------------------- af0815 · 2021-02-17 16:50 Your baseframe is not a Frame, it is a normal Form. Give your Box1 and Button1 a valid parent. ---------------------------------------------------------------------- howardpc · 2021-02-17 17:36 If you really want to use dynamically adapted frames (not forms) as containers in your dynamically created tabsheets, the attached project might get you started. ---------------------------------------------------------------------- andyH · 2021-02-17 20:12 QuoteYour baseframe is not a Frame, it is a normal Form.Error on my part, just one of several iterations. Changed TForm to TFrame, compiled, runtime error Project project1 raised exception class 'EResNotFound' with message: Resource Tbaseframe not found There is no unit2.lfm, but I thought that was what RequireDerivedFormResource:=false in the main program file was supposed to deal with. Parents - there is no parent defined for mybutton or box1 in the example created with the form designer that worked. QuoteIf you really want to use dynamically adapted frames (not forms) as containers in your dynamically created tabsheets, the attached project might get you started.howardpc - thanks for taking the trouble with the example, downloaded, extracted, open > framesExample.lpr > open project. Access violation. Abort kills lazarus, ok results in no source editor and if I try and compile it, it opens unit1.lfm with an error unit1.lfm(1,7) Fatal: Syntax error, "BEGIN" expected but "OBJECT" found. I can open the files in my text editor, but there is a limit to understanding what the example does without seeing it run. Running lazarus 2.0.2 under linux. Not sure I understand dynamically adapted frames and dynamically created tabsheets. The real application has 4 tabs and about 12 objects in each tab, they are fixed in that they cannot be changed by the user. I'm just trying to use TFrames as containers for the objects so that they can live in different units rather than having them all defined in the main form. And not have to use the form designer to do it. ---------------------------------------------------------------------- howardpc · 2021-02-17 22:47 Quote from: andyH on February 17, 2021, 09:12:00 pmhowardpc - thanks for taking the trouble with the example, downloaded, extracted, open > framesExample.lpr > open project. Access violation. Delete whatever you unpacked and tried to compile before. Don't open the .lpr. Unzip the attachment anew. Use Project > Open Project and open framesExample.lpi ---------------------------------------------------------------------- andyH · 2021-02-17 23:45 Deleted the existing folder and files, extracted again - image 1. In lazarus open > project > framesExample.lpi Source editor disappeared, tried to compile - image 2. EDIT - could this be a win/linux format issue or incompatible res file? ---------------------------------------------------------------------- trev · 2021-02-18 00:05 Sounds to me like the project was saved from a Lazarus trunk version without the Project Options > Miscellaneous > Maximise compatibility of project files option being enabled. ---------------------------------------------------------------------- GAN · 2021-02-18 00:11 @howardpc I can't open it. The IDE is empty. ---------------------------------------------------------------------- andyH · 2021-02-18 00:34 @GAN - another mint user? Currently running LM19.0 cinnamon. ---------------------------------------------------------------------- GAN · 2021-02-18 00:52 Quote from: andyH on February 18, 2021, 01:34:59 am@GAN - another mint user? Currently running LM19.0 cinnamon. Sure! Linux Mint 19.3 Mate, very stable BTW. ---------------------------------------------------------------------- af0815 · 2021-02-18 06:38 Quote from: andyH on February 17, 2021, 09:12:00 pmParents - there is no parent defined for mybutton or box1 in the example created with the form designer that worked. The binding of the rigth parent is normally done with the information inside the lfm. If you place a visible object by yourselft, you have to do the work of the designer in code and set the correct parent of your control. Because the owner must not be the parent. And dont change a TForm into TFrame and verce visa. Normally you have to deal with the lfm in a correct manner too. If you mix creating by hand and designer you will fast get scrap. ---------------------------------------------------------------------- howardpc · 2021-02-18 09:02 trev is correct, the project zip I shared was not saved with maximum compatibility. Try this attachment which hopefully runs in non-trunk versions of Lazarus. ---------------------------------------------------------------------- andyH · 2021-02-18 17:11 @howardpc, thanks that worked, I can see what it does and how to use it.