Recent

Author Topic: LAMW : second window makes app crash  (Read 1637 times)

SuperCyprien

  • New member
  • *
  • Posts: 8
LAMW : second window makes app crash
« on: December 31, 2023, 03:54:42 pm »
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][+][-]
  1. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  2.    var mod2 : TAndroidModule2;
  3. begin
  4.   mod2.Create(Self);
  5.   mod2.Show;
  6.   mod2.Free;
  7. 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

  • Jr. Member
  • **
  • Posts: 51
Re: LAMW : second window makes app crash
« Reply #1 on: December 31, 2023, 04:47:08 pm »
try this



Code: Pascal  [Select][+][-]
  1. uses
  2.     unit2;
  3. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  4. begin
  5.   if AndroidModule 2 = nill then
  6.   begin
  7.     gApp.CreatForm(TAndroidModule2, AndroidModule2);
  8.     AndroidModule2.init;
  9.   end;
  10.   AndroidModule2.Show;
  11. end;
  12.  
  13.  
  14.  
  15.  
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

SuperCyprien

  • New member
  • *
  • Posts: 8
Re: LAMW : second window makes app crash
« Reply #2 on: December 31, 2023, 04:53:44 pm »
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][+][-]
  1. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  2. begin
  3.   if AndroidModule2 = nil then
  4.   begin
  5.     gApp.CreateForm(TAndroidModule2, AndroidModule2);
  6.     AndroidModule2.init;
  7.   end;
  8.   AndroidModule2.Show;
  9. end;
  10.  

I can't open the second screen more than one time, but I will work at this now :)

c4p

  • Full Member
  • ***
  • Posts: 170
Re: LAMW : second window makes app crash
« Reply #3 on: December 31, 2023, 05:50:01 pm »
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.

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][+][-]
  1. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  2. begin
  3.   if AndroidModule2 = nil then
  4.   begin
  5.     gApp.CreateForm(TAndroidModule2, AndroidModule2);
  6.     AndroidModule2.init;
  7.   end;
  8.   AndroidModule2.Show;
  9. end;
  10.  

I can't open the second screen more than one time, but I will work at this now :)
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle.

SuperCyprien

  • New member
  • *
  • Posts: 8
Re: LAMW : second window makes app crash
« Reply #4 on: December 31, 2023, 05:54:12 pm »
I did that and it works !
Thank you !!

c4p

  • Full Member
  • ***
  • Posts: 170
Re: LAMW : second window makes app crash
« Reply #5 on: December 31, 2023, 05:54:52 pm »
Cool, great!  :)

For clarity if anyone else needs it, something like this:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.TAndroidModule1JNIPrompt(Sender: TObject);
  2.  begin
  3.   if AndroidModule2 = nil then
  4.   begin
  5.     gApp.CreateForm(TAndroidModule2, AndroidModule2);
  6.     AndroidModule2.init;
  7.   end;
  8.  End;

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  2.  begin
  3.   AndroidModule2.Show;
  4.  End;

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule2.Button1Click(Sender: TObject);
  2.  begin
  3.   AndroidModule2.close;
  4.  End;

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][+][-]
  1. procedure TAndroidModule1.ImageView1Click(Sender: TObject);
  2. begin
  3.   if AndroidModule2 = nil then
  4.   begin
  5.     gApp.CreateForm(TAndroidModule2, AndroidModule2);
  6.     AndroidModule2.init;
  7.   end;
  8.   AndroidModule2.Show;
  9. end;
  10.  

I can't open the second screen more than one time, but I will work at this now :)
« Last Edit: December 31, 2023, 05:57:01 pm by c4p »
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle.

rafman

  • New Member
  • *
  • Posts: 10
Re: LAMW : second window makes app crash
« Reply #6 on: December 31, 2023, 06:20:07 pm »
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][+][-]
  1.  
  2. if AndroidModule2 = nil then
  3. begin
  4.   gApp.CreateForm(TAndroidModule2, AndroidModule2);
  5.   AndroidModule2.InitShowing();
  6. end
  7. else
  8.   AndroidModule2.Show();
  9.  

 

TinyPortal © 2005-2018