Problem with form to be called with ShowModal lazarus / 10-Designer ---------------------------------------------------------------------- Ever · 2016-02-24 02:24 Hello friends     This is my first topic, not fluent in English so I written here is translated by Google Translate.     I present the following problem. I have two forms called form1 and form2, form2 is called by ShowModal from form1, but for reasons not understood achievement by showing the form2 the first (form1) disappears from the screen. This behavior did not have it with version 1.4.4 but after upgrading to version 1.6.0 began presenting this problem.     Thanks in advance for any suggestions they can provide. ---------------------------------------------------------------------- balazsszekely · 2016-02-24 04:30 Please attach a zipped demo application which demonstrates the problem(source only!). ---------------------------------------------------------------------- Ever · 2016-02-24 11:52 Thank you, including small project that demonstrates the behavior ---------------------------------------------------------------------- balazsszekely · 2016-02-24 12:13 Tested both under win32/64 and gtk2(Lazarus trunk/fpc 3.0.0,). I cannot reproduce. https://youtu.be/V4XhZm5vmn4 ---------------------------------------------------------------------- zeljko · 2016-02-24 12:18 @everjdelgadoch, what operating system and widgetset do you use ? Is it virtual or regular machine ? ---------------------------------------------------------------------- balazsszekely · 2016-02-24 12:21 Works under OSX too. It must be raspberry pi. ---------------------------------------------------------------------- frakno · 2016-02-24 12:32 It is obviously a windows problem because I can reproduce it. I will look around in my files I think I've got a solution. if I find it I'll post it immediately ---------------------------------------------------------------------- frakno · 2016-02-24 12:46 Put into your Unit2 section uses   ..., LCLType, Windows;  type   { TForm2 }   TForm2 = class(TForm) ...   protected       procedure CreateParams(var params: TCreateParams);override; and in the implementation procedure TForm2.CreateParams(var Params: TCreateParams); begin   inherited CreateParams(params);   Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;   Params.WndParent := GetDesktopWindow; end;  and problem should be solved ---------------------------------------------------------------------- Noodly · 2016-02-24 13:02 Assign form1 as the popupparent of form2 before you showmodal:     form2.PopupParent:=Form1; ---------------------------------------------------------------------- balazsszekely · 2016-02-24 13:11 @frakno, @Noodly According to the OP Form1 disappears not Form2. Form2 is not the issue here. ---------------------------------------------------------------------- rvk · 2016-02-24 13:21 Quote from: GetMem on February 24, 2016, 02:11:10 pm@frakno, @Noodly According to the OP Form1 disappears not Form2. Form2 is not the issue here. Maybe not. But it DOES work !! (I can reproduce this bug here too, Lazarus 1.6/win64) Maybe it's because when Form1 is assigned to Form2.popup or parent, it will not hide. But the fact it hides when Form2.ShowModal is called seems like a real bug. ---------------------------------------------------------------------- frakno · 2016-02-24 13:27 GetMem To my understanding. If I run his program Form3 appears, then I press button -> Form1 appears, and if I press Button call Form2 , then Form 2 appears and  !!! Form1 disappears  !!! If you try my advice and put my code into unit2  you will see ... that it helps ---------------------------------------------------------------------- balazsszekely · 2016-02-24 13:29 Quote@rvk I can reproduce this bug here too, Lazarus 1.6/win64Can you please test it with trunk? Because Ondrej worked lately with some similar issues, maybe he fixed already. I only tested with trunk in different OS, the bug is not present. @frakno I'm not saying is not true, but I wasn't able to reproduce the bug. Anyway this should not happen. If it does, like @rvk said it's a real nasty bug. ---------------------------------------------------------------------- rvk · 2016-02-24 13:35 Quote from: GetMem on February 24, 2016, 02:29:34 pmCan you please test it with trunk? Because Ondrej worked lately with some similar issues, maybe it's fixed already. I only tested with trunk in different OS, the bug is not present.Trunk works fine. I also see what's happening now... (Form3 is main, Form1 is second form and Form2 is modal form) When Form2 is shown modal then Form3 (mainform) is put in front of Form1 (which makes it not visible anymore). If you move the windows (form3) at the start of the program you can see that Form1 stays visible. It has something to do with the SetZOrder() in TControl.BringToFront where Form3 gets put in front of Form1. (see attached image) ---------------------------------------------------------------------- balazsszekely · 2016-02-24 13:43 Quote@rvk I also see what's happening now... (Form3 is main, Form1 is second form and Form2 is modal form) When Form2 is shown modal then Form3 (mainform) is put in front of Form1 (which makes it not visible anymore). If you move the windows (form3) at the start of the program you can see that Form1 stays visible. It has something to do with the SetZOrder() in TControl.BringToFront where Form3 gets put in front of Form1. (see attached image)Oh,  I see now! I wasn't paying attention which is the main form, because everything worked fine. Since it's already fixed in the trunk, there is nothing we can do. ---------------------------------------------------------------------- Noodly · 2016-02-24 14:25 @getmem I believe that assigning form2.PopupParent:=form1 solves the OPs problem in the example he gave, but whether or not there is a more fundamental underlying Z order issue with modal forms is another question. ---------------------------------------------------------------------- Ever · 2016-02-24 15:50 I solved the problem by following the advice of placing form2 PopupParent: = Form1. Forget to mention that use Windows 10. Thank you all for your cooperation ---------------------------------------------------------------------- FTurtle · 2016-02-24 21:41 Quote from: everjdelgadoch on February 24, 2016, 04:50:33 pmI solved the problem by following the advice of placing form2 PopupParent: = Form1. Other way: Set for TForm2 in designer: PopupMode:=pmAuto I think this way is better, because it works for all instances of TForm2 and does not require an explicit code for each call. In general, PopupParent should not be set in designer because: 1. Different forms (classes and instanses) may call this form. 2. Global variable may be not used at all.