LAMW : second window makes app crash lazarus / 43-Android ---------------------------------------------------------------------- SuperCyprien · 2023-12-31 14:54 Hello, I've just discovered LAMW and I try to code my first app. I ever know (a little bit) Lazarus and freepascal , even if I have not really used them for 5 ou 6 years. I would like to make an app with two windows, not opened at the same time. On the first "screen", I have a "button" (an Image) to launch the second screen. The code I wrote is : 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 TAndroidModule1.ImageView1Click(Sender: TObject);   var mod2 : TAndroidModule2;begin  mod2.Create(Self);  mod2.Show;  mod2.Free;end; When I click on the Image, the app crashes. Sure I do something wrong, but what ? I didn't find so much doc on these components, so help would be very appreciated. Sorry for my poor english, I'm french Thank you for advance, Cyprien ---------------------------------------------------------------------- marcos-ebm · 2023-12-31 15:47 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 uses    unit2;procedure TAndroidModule1.ImageView1Click(Sender: TObject);begin  if AndroidModule 2 = nill then  begin    gApp.CreatForm(TAndroidModule2, AndroidModule2);    AndroidModule2.init;  end;  AndroidModule2.Show;end; ---------------------------------------------------------------------- SuperCyprien · 2023-12-31 15:53 Thank you. It is better and the app do not crash now. Just some corrections in case of someone else had the same problem : 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 TAndroidModule1.ImageView1Click(Sender: TObject);begin  if AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.init;  end;  AndroidModule2.Show;end;  I can't open the second screen more than one time, but I will work at this now ---------------------------------------------------------------------- c4p · 2023-12-31 16:50 Try putting the second window creation code in the OnJNIPrompt event and call it with AndroidModule2.Show when required and close with AndroidModule2.close to see if that helps, that way it creates the window on startup and lets you open/close the form/window when you need it. Quote from: SuperCyprien on December 31, 2023, 04:53:44 pmThank you. It is better and the app do not crash now. Just some corrections in case of someone else had the same problem : 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 TAndroidModule1.ImageView1Click(Sender: TObject);begin  if AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.init;  end;  AndroidModule2.Show;end;  I can't open the second screen more than one time, but I will work at this now ---------------------------------------------------------------------- SuperCyprien · 2023-12-31 16:54 I did that and it works ! Thank you !! ---------------------------------------------------------------------- c4p · 2023-12-31 16:54 Cool, great!  For clarity if anyone else needs it, something like 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 procedure TAndroidModule1.TAndroidModule1JNIPrompt(Sender: TObject); begin   if AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.init;  end; End; 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 TAndroidModule1.ImageView1Click(Sender: TObject); begin  AndroidModule2.Show; End; 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 TAndroidModule2.Button1Click(Sender: TObject); begin   AndroidModule2.close; End; Quote from: SuperCyprien on December 31, 2023, 04:53:44 pmThank you. It is better and the app do not crash now. Just some corrections in case of someone else had the same problem : 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 TAndroidModule1.ImageView1Click(Sender: TObject);begin  if AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.init;  end;  AndroidModule2.Show;end;  I can't open the second screen more than one time, but I will work at this now ---------------------------------------------------------------------- rafman · 2023-12-31 17:20 Try This directly from your Image onclick() event, works for me  (LAMW 0.8.6.3) Add the second unit declaration after the implementation section of unit1  as : implementation uses   unit2, unit_3, ...;  // you can add more than one units in order to open several forms and finally add this code your Image onclick() event on first unit. 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  if AndroidModule2 = nil thenbegin  gApp.CreateForm(TAndroidModule2, AndroidModule2);  AndroidModule2.InitShowing();endelse  AndroidModule2.Show();