With parent use, how to dynamically create a Tform in another Tform with Linux? lazarus / 31-LCL ---------------------------------------------------------------------- GillesH · 2017-04-10 13:16 Hello, the example "Creating a new form dynamically" of http://wiki.freepascal.org/Form_Tutorial doesn't work if I write : 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 procedure TForm1.Button1Click(Sender: TObject);var  MyForm: TForm;begin  MyForm:=TForm.Create(nil);               MyForm.SetBounds(100, 100, 220, 150);    MyForm.Caption:='My dynamic created form';   MyForm.Parent := Form1; //<--- !   MyForm.ShowModal;                      FreeAndNil(MyForm);     end;OK with Windows but not with Ubuntu 16.4 - Lazarus 1.6.4 - FPC 3.0.2 - x86_64-linux.gtk2. Regards. Gilles ---------------------------------------------------------------------- rvk · 2017-04-10 13:54 What doesn't work? Please describe the problem. And why are you using a parent for the MyForm if you are going to use ShowModal. ShowModal shows the form over all other forms disabling them. So you could just do 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 var  MyForm: TForm;begin  MyForm:=TForm.Create(nil);              try    MyForm.SetBounds(Self.Left + 100, Self.Top + 100, Self.Left + 220, Self.Top + 150);      MyForm.Caption:='My dynamic created form';    MyForm.ShowModal;                      finally    FreeAndNil(MyForm); end; No need to make Form1 parent for the MyForm. ---------------------------------------------------------------------- HeavyUser · 2017-04-10 14:02 Quote from: GillesH on April 10, 2017, 03:16:01 pmHello, the example "Creating a new form dynamically" of http://wiki.freepascal.org/Form_Tutorial doesn't work if I write : 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 procedure TForm1.Button1Click(Sender: TObject);var  MyForm: TForm;begin  MyForm:=TForm.Create(nil);               MyForm.SetBounds(100, 100, 220, 150);    MyForm.Caption:='My dynamic created form';   MyForm.Parent := Form1; //<--- !   MyForm.ShowModal;                      FreeAndNil(MyForm);     end;OK with Windows but not with Ubuntu 16.4 - Lazarus 1.6.4 - FPC 3.0.2 - x86_64-linux.gtk2. Regards. Gilles Form1 is a variable might or might not point to the form your code executes from. Never use the global variables especially in a dynamic environment where more than one instances of a form can be created. In your case change Form1 to self. Other than that  you have two major mistakes. 1) you forget about the forms placement on the screen which is used as form1 client coordinates moving the form probably outside the form1'a visible window. 2) once a form have a parent can not be "shown" it can only be made visible and the parent is "shown". And as a last precaution make sure that myform has no borders or caption bar to avoid some nusty surprises down the road. ---------------------------------------------------------------------- GillesH · 2017-04-10 14:13 Sorry, i don't understand. I use the example of the wiki to highlight  the problem of parent. Here are excerpts from my 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 procedure TForm1.Button1Click(Sender: TObject); var  F01, F02, F03, F04, F05, F06, F07, F08, F09, F10: TForm;  F11, F12, F13, F14, F15, F16, F17, F18, F19, F20: TForm;  F21, F22, F23, F24: TForm;  nCol, nRow, nWidth, nHeight, iCol, iRow : Integer;begin  showmessage(IntToStr(Form1.Client Width)+'*'+IntToStr(Form1.ClientHeight)+'|'+  IntToStr(Form1.Width)+'*'+IntToStr(Form1.Height));  F01:= TForm.Create(Application);  F01.Parent := Self;  F02:= TForm.Create(Application);  F02.Parent := Self;  F03:= TForm.Create(Application);  F03.Parent := Self;  F04:= TForm.Create(Application);  F04.Parent := Self;   [...] with F01 do  begin    SetBounds((icol-1)*(nwidth+16), (iRow -1) * (nheight+38), nwidth, nHeight);   Show;  end;  [...]Please look at attachmnt [Windows result] Avantage of Parent : All Fxx are moving with Form1. So i can remove the Parent with Ubuntu. Fxx appears. (Form1.Left+...) But if Form1 moves, you must add code to move Fxx. Thanks. Gilles ---------------------------------------------------------------------- rvk · 2017-04-10 14:18 Quote from: GillesH on April 10, 2017, 04:13:24 pmi don't understand. I use the example of the wiki to highlight  the problem of parent. Ok, now I understand. But you STILL haven't said what the problem under Ubuntu is. (just saying Windows is OK but Ubuntu not isn't really a helpful description) ---------------------------------------------------------------------- GillesH · 2017-04-10 14:29 Oups ! Sorry but my english is poor. I install a Kubuntu on my Virtual Box to test the same code. ---------------------------------------------------------------------- GillesH · 2017-04-11 08:44 Hello, Test with Kubuntu 16.04 [64] -Lazarus 1.6.4 [2017-02-26]-FPC 3.0.2 [64 bits]. 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 rocedure TForm1.Button1Click(Sender: TObject);var  F01: TForm;  F02: TF02;begin   F01:= TForm.Create(Application);  //LCLIntf.SetParent(F01.Handle, self.Handle);   with F01 do  begin    Color:= clRed;    SetBounds(0, 30, 300, 200);    Parent := Self;    Show;  end;   Application.CreateForm(TF02, F02);  with F02 do  begin    Color:= clGreen;    SetBounds(340, 30, 300, 200);    Parent := Self;    Show;  end; end; Result in attachments :  better but not that !  BorderIcons, BorderStyle !  F01, F02 : are they Popups ? regards. Gilles ---------------------------------------------------------------------- rvk · 2017-04-11 08:47 Looks fine to me. You STILL haven't explained what the problem is. ---------------------------------------------------------------------- Thaddy · 2017-04-11 08:54 Create some graphics that you would expect, plz. I can't see what you mean? ---------------------------------------------------------------------- GillesH · 2017-04-11 09:22 Yes... Impossible to display TitleBar, Icon System even using Caption, BorderStyle, BorderIcon. F02 has the same properties as TForm1 (default properties). And the display of the 2 forms (Form1 and F02) is very different. F01 and F02 look like Popups. If you remove Parent := self, F01 and F02 appear with the expected design. ---------------------------------------------------------------------- balazsszekely · 2017-04-11 10:00 This is the limitation of the window manager itself not lazarus. If I understand you correctly you try to create a MDI like application? ---------------------------------------------------------------------- rvk · 2017-04-11 10:01 Quote from: GillesH on April 11, 2017, 11:22:49 amImpossible to display TitleBar, Icon System even using Caption, BorderStyle, BorderIcon. F02 has the same properties as TForm1 (default properties).Ah, finally an explanation. Yes, the lack of caption, icons and border is intended behavior in Lazarus under gtk2. When Parent <> nil for a TForm, under gtk2, a gtk_hbox is created (without caption, icons and border). When Parent = nil, a gtk_window (with all its properties) is created. ---------------------------------------------------------------------- GillesH · 2017-04-11 10:11 OK. I understand. It's related to how gtk2 works. The behavior of Lazarus windows is very different in this case of Lazarus LinuxMuch differentiation in perspective. Thanks for the help. Regards. Gilles ---------------------------------------------------------------------- Thaddy · 2017-04-11 10:13 1. It is not related to Lazarus but to GTK2 itself...... Didn't you read... Try C++, same effect.... 2. Lazarus obeys the principles of its underlying widget sets, in your case GTK2 Don't turn the world upside down. This is a GTK2 issue. Not a Lazarus one.... Naive programmers coming from Windows, I suppose, again. Read first. Ask later. ---------------------------------------------------------------------- GillesH · 2017-04-11 10:47 Yes, that's what I wrote at the beginning.  I'am not going to start by thwarting you. So I corrected  . But I have proof to contrary. Look at the attachment : (Qt 5.8 example) on the same VirtualBox session. Lazarus has no MDI. This clearly complicates my project... and with SDIi you have a curious choice :   - parent without caption, icons and border   - caption, icons and border without parent Quote from: Thaddy on April 11, 2017, 12:13:43 pmNaive programmers coming from Windows, I suppose, again. No from Qt on WIndows, Linux, os X, Androïd ond iOS. I was using Lazarus/delphi 10 years ago. I make a little detour by Lazarus today... friendly,  without aggressiveness. You see, you think it is not feasible, I do not qualify this approach as naive : Lazarus doest not allow it easily. It will be a little more complicated. That's all. Regards. Gilles ---------------------------------------------------------------------- rvk · 2017-04-11 11:05 Quote from: GillesH on April 11, 2017, 12:47:02 pmBut I have proof to contrary. Look at the attachment : (Qt 5.8 example) on the same VirtualBox session. Lazarus has no MDI. This clearly complicates my project. No, you don't have proof. What you are showing aren't real GTK2-windows at all. When you run this example... are the icons for close, etc on the left or the right?? What you are showing is just a simulation of MDI (with the icons in the wrong place). See attached screenshot. You can do something similar with Lazarus. See http://wiki.lazarus.freepascal.org/MultiDoc ---------------------------------------------------------------------- GillesH · 2017-04-11 11:17 Hum difficult to say : With Qt you can change the presentation of the windows and by example the native order of the buttons following the OS. I will look at what exactly it is. But assuming you are right, Qt offers an actually solution. MultiDoc Wiki : Since 2012 this component is replaced by Multiframe, using docked frames for the same functionality. yes but what difficulty to use. Regards. Gilles. ---------------------------------------------------------------------- GillesH · 2017-04-15 09:26 Hello, Problem almost* solved with my pseudo mdi. I have not tested on mac OS : when I install Qt, lazarus previously installed no longer works (!?). I then have to uninstall Qt and Lazarus and reinstall Lazarus completely. Curiously, I had to differentiate the Ubuntu code from the Debian code when fMain.WindowState = wsMaximized.  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 {$IFDEF UBUNTU}if aFormMaximized then Y := Y - hTitleBar;{$ENDIF} I mainly use : 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   procedure WMMove(var Message: TLMMove); message LM_MOVE;  procedure WMSize(var Message: TLMSize); message LM_SIZE;   [...]  wBorder := max(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CXBORDER));  hBorder := max(GetSystemMetrics(SM_CYEDGE), GetSystemMetrics(SM_CYBORDER));  wScrollBar :=  GetSystemMetrics(SM_CXHSCROLL);  hTitleBar :=  GetSystemMetrics(SM_CYCAPTION); Regards. Gilles * : I do not need the "Overlapped" display so I have not developed it. Screenshots : Debian 8.7 [Laz 64] - Ubuntu 16.04 [Laz 64] - Windows 7 [Laz 32]