Recent

Author Topic: Lamw(solved) - Strange behavior  (Read 1974 times)

marcos-ebm

  • Jr. Member
  • **
  • Posts: 51
Lamw(solved) - Strange behavior
« on: January 15, 2024, 08:29:11 am »
[using the translator]

when creating the second form using the command
Code: Pascal  [Select][+][-]
  1.    
  2.     if AndroidModule2 = nil then
  3.     begin
  4.         gApp.CreateForm(TAndroidModule2, AndroidModule2);
  5.         AndroidModule2.Init;
  6.     end;
  7.     AndroidModule2.Show;
  8.  

the second form is appearing with the components of the first form, that is, the second form appears with the button from the first form

Has anyone ever experienced this?
« Last Edit: January 15, 2024, 10:44:14 am by marcos-ebm »
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

vangli

  • Jr. Member
  • **
  • Posts: 57
Re: Lamw - Strange behavior
« Reply #1 on: January 15, 2024, 08:43:41 am »
How is TAndroidModule2 defined?
Regards Bent

marcos-ebm

  • Jr. Member
  • **
  • Posts: 51
Re: Lamw - Strange behavior
« Reply #2 on: January 15, 2024, 08:48:12 am »
How is TAndroidModule2 defined?

within a button click, but I've already tried adding activityCreate, JNIPrompt, but the behavior is always the same
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

vangli

  • Jr. Member
  • **
  • Posts: 57
Re: Lamw - Strange behavior
« Reply #3 on: January 15, 2024, 08:54:00 am »
Pls show code of class definition?

Edited: And think about inheritanse.
« Last Edit: January 15, 2024, 09:00:50 am by vangli »
Regards Bent

c4p

  • Full Member
  • ***
  • Posts: 170
Re: Lamw - Strange behavior
« Reply #4 on: January 15, 2024, 09:16:46 am »
I would define the creation of the second form in event OnJNIPrompt of AndroidModule1 then call your second form show from a button click event in AndroidModule1.
This creates the second form on start, allowing you to then to show the second form from your button without issue.

Code: Pascal  [Select][+][-]
  1. procedure AndroidModule1.AndroidModule1JNIPrompt(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 AndroidModule1.Button1Click(Sender: TObject);
  2. begin  
  3.     AndroidModule2.Show;
  4. end;
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.

marcos-ebm

  • Jr. Member
  • **
  • Posts: 51
Re: Lamw - Strange behavior
« Reply #5 on: January 15, 2024, 09:20:39 am »
Pls show code of class definition?

Edited: And think about inheritanse.

ok, When I get home I'll post it



I would define the creation of the second form in event OnJNIPrompt of AndroidModule1 then call your second form show from a button click event in AndroidModule1.
This creates the second form on start, allowing you to then to show the second form from your button without issue.

Code: Pascal  [Select][+][-]
  1. procedure AndroidModule1.AndroidModule1JNIPrompt(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 AndroidModule1.Button1Click(Sender: TObject);
  2. begin  
  3.     AndroidModule2.Show;
  4. end;

I've done it the same way as you, but the behavior remains the same
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Lamw - Strange behavior
« Reply #6 on: January 15, 2024, 09:25:38 am »
the second form is appearing with the components of the first form, that is, the second form appears with the button from the first form

Choose some background color for second form (change Background property of form). If you leave it at default, Android considers background as transparent and shows previous form underneath.
« Last Edit: January 15, 2024, 09:27:45 am by dseligo »

c4p

  • Full Member
  • ***
  • Posts: 170
Re: Lamw - Strange behavior
« Reply #7 on: January 15, 2024, 09:56:03 am »
Also try calling below before showing the form in case it's a Z-order visibility issue.

Code: Pascal  [Select][+][-]
  1. AndroidModule2.MoveTaskToFront;

The post below regarding background/transparency of the AndroidModule2 form is a good call and worth checking too.

the second form is appearing with the components of the first form, that is, the second form appears with the button from the first form

Choose some background color for second form (change Background property of form). If you leave it at default, Android considers background as transparent and shows previous form underneath.
« Last Edit: January 16, 2024, 02:34:31 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.

marcos-ebm

  • Jr. Member
  • **
  • Posts: 51
Re: Lamw - Strange behavior
« Reply #8 on: January 15, 2024, 10:44:00 am »
Guys, I would like to thank everyone for their help

vangli
c4p
dseligo

The problem was solved thanks to dseligo's tip, thank you very much
Lazarus 3.0 / LAMW 0.8.6.4 - Gradle 8.5 - Jdk 21 - Ndk 21e - Windows 11

c4p

  • Full Member
  • ***
  • Posts: 170
Re: Lamw(solved) - Strange behavior
« Reply #9 on: January 15, 2024, 02:25:16 pm »
Good shout @dseligo  8-)
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.

 

TinyPortal © 2005-2018