[SOLVED] Second form does not show until clicked on the dock icon lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- ling · 2021-03-12 08:21 I have a project there are multiple forms, I encounter a problem on form show. When the application starts, the main form shows, I click a menu item to open a second form, main form is deactivate but the second form does not show. The only way to bring form to show is clicking on the application dock icon. The second form is not specific, every form in my project has the same situation. I tried to reproduce the situation by a simple project, but the simple project is working fine. Any idea for debugging this problem? -- Lazarus version: 2.0.6 FPC: 3.0.4 macOS Catalina 10.15.7 ---------------------------------------------------------------------- balazsszekely · 2021-03-12 08:45 @ling How do you create the second form? Dynamically? Is there any code on the second form's OnCreate, OnShow, OnActivate event? Best is to attach a simplified version of your project, where the issue is clearly reproducible. ---------------------------------------------------------------------- ling · 2021-03-12 09:29 @GetMem Thanks. I just create a simple form dynamically: 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 TForm1.MenuItem1Click(Sender: TObject);var  aform: TForm;begin  aform:=TForm.Create(Self);  aform.Show;end;  I'm still trying to strip the project, but it is complicated, the codes are bundled. The project is developing by several people and originally on Windows. I will attach then simplified version when it is done. ---------------------------------------------------------------------- dseligo · 2021-03-12 10:13 You have to declare variable aform global, not in procedure. Or, you can try this: 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 TForm1.MenuItem1Click(Sender: TObject);var  aform: TForm;begin  aform:=TForm.Create(nil);  try    aform.ShowModal;  finally    aform.Free;  end;end; ---------------------------------------------------------------------- ling · 2021-03-13 04:57 @dseligo Thanks. It's a sample code. I have tried global variable too, the same situation. ShowModal works fine, but that will block other operations, not what I want. ---------------------------------------------------------------------- winni · 2021-03-13 10:54 Hi! Replace  aform.ShowModal; with  aform.Show; That is the whole secret. Winni ---------------------------------------------------------------------- lucamar · 2021-03-13 13:53 Quote from: winni on March 13, 2021, 11:54:05 amReplace  aform.ShowModal; with  aform.Show; That is the whole secret. AFAIU, it seems to be also the whole problem: if he uses Show the new form will appear behind the caller and he has to bring it to front by clicking on the dock; isn't that it? ---------------------------------------------------------------------- balazsszekely · 2021-03-13 14:24 Then perhaps setting the second form's PopupMode property to pmExplicit and PopupParent to main form solves the issue. Also in worse case scenario FormStyle property can be changed to fsStayOnTop. PS: Under normal circumstances none of the above should be necessary. ---------------------------------------------------------------------- winni · 2021-03-13 17:44 Quote from: lucamar on March 13, 2021, 02:53:03 pm AFAIU, it seems to be also the whole problem: if he uses Show the new form will appear behind the caller and he has to bring it to front by clicking on the dock; isn't that it? Hi! aForm.show brings the Form to the front. If it is inbetween hidden by other Forms another aForm.show brings this Form again to the front. Winni ---------------------------------------------------------------------- MarkMLl · 2021-03-13 18:05 Cleverness of this sort troubles me, I've tried it too many times myself. I think OP should be looking very carefully at how forms are normally created in the .lpr during program startup: it's not a straight Create. MarkMLl ---------------------------------------------------------------------- Fred vS · 2021-03-13 18:07 Hello. And what about this one ?: 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  Form1: TForm1;  aform: TForm; implementation {$R *.lfm} { TForm1 } procedure TForm1.MenuItem1Click(Sender: TObject);begin  if not assigned(aform) then aform := TForm.Create(nil);  aform.visible := true;  aform.BringToFront;end; procedure TForm1.FormDestroy(Sender: TObject);begin  if assigned(aform) then aform.free;end; ---------------------------------------------------------------------- lucamar · 2021-03-13 20:26 Quote from: MarkMLl on March 13, 2021, 07:05:59 pmI think OP should be looking very carefully at how forms are normally created in the .lpr during program startup: it's not a straight Create. No, it isn't. It's a call to Application.CreateForm(). But IIRC that's basically so that the application can keep the list of forms and close itself when the main one is exited (yeah, I know it's not just that but that's its main function, IIRC). The question really is that however a form is created (and let's remember that e.g. most dialogs---the "simple" ones, I mean: InputBox, etc.---are created with a simple call to Create), a call to Show should, as Winni said, also bring it to the front, but according to the OP it doesn't (at least in macOS) in his program. ---------------------------------------------------------------------- trev · 2021-03-13 22:28 If none of the above help solve your issue, you are going to have to provide the code which causes this behaviour. ---------------------------------------------------------------------- cdbc · 2021-03-14 12:10 Hi My 2 cents: Lazarus does it very well  Why not have a look at the source-code? Regards Benny ---------------------------------------------------------------------- skalogryz · 2021-03-14 14:55 Quote from: ling on March 12, 2021, 09:21:03 amI have a project there are multiple forms, I encounter a problem on form show. -- Lazarus version: 2.0.6 I'd think Lazarus version you're using has the problem. You might want to try to compile the app on the later version of Lazarus. ---------------------------------------------------------------------- ling · 2021-03-15 07:51 @skalogryz Thanks! I updated lazarus version to 2.0.12, fpc to 3.2.0, it works fine now.