Android:call one form from another lazarus / 43-Android ---------------------------------------------------------------------- mirce.vladimirov · 2025-08-19 13:49 Please what is the proper way that one form can be called and shown on certain user action,  do something in the called form and then go back to the form that called it ? One more: Is there a way that only a procedure or function on form2 can be called from form1 without showing form2 ? God knows I was messing for two days with DeepSeek and ChatGPT but so far i am getting more and more bullshit. My best result was showing called form over the one that called it, so nothing can be read. I work under win10, i use Lazarus 3.4 + LAMW, I do application programing with Lazarus for use under Linux and Windows  since 2009 but never for Android so far. ---------------------------------------------------------------------- dseligo · 2025-08-19 18:32 Quote from: mirce.vladimirov on August 19, 2025, 03:49:29 pmMy best result was showing called form over the one that called it, so nothing can be read. You are probably on a good way. Set BackgroundColor property of the form(s). ---------------------------------------------------------------------- Lazarinr · 2025-09-01 00:01 1. Add the name of unit2 in Uses: 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  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils, AndroidWidget, Laz_And_Controls, framelayout, stablayout,  tablelayout, linearlayout, unit2; 2. To call the form when the user clicks the button: 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.Button1Click(Sender: TObject);begin   // created the form if not exist   if AndroidModule2 = nil then gApp.CreateForm(TAndroidModule2,AndroidModule2);   // Show the form   AndroidModule2.InitShowing;end; 3. Executes a procedure that is in form2 without having to open it: 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.Button2Click(Sender: TObject);begin   // created the form if not exist   if AndroidModule2 = nil then gApp.CreateForm(TAndroidModule2,AndroidModule2);   // Excute procedure   AndroidModule2.ProcedureOfForm2;end; ---------------------------------------------------------------------- mirce.vladimirov · 2025-11-26 14:42 This is what i got, in "uses" : 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  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils, AndroidWidget, Laz_And_Controls,   ZConnection, ZDataset,  And_jni,   framelayout, stablayout, tablelayout, linearlayout , unit2   ;  and then when I call AndroidModule2 :  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 then     gApp.CreateForm(TAndroidModule2, AndroidModule2);  AndroidModule2.MoveTaskToFront();  AndroidModule2.BackgroundColor:=colbrWhite;  AndroidModule2.InitShowing;      And then the called module (form) is shown. From that one , i want to go back, exti from AndroidMdule2 to AndroidModule1 : 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  self.Finish;end; Called form2 is displayed, works as expected. When i press the button to go back to form1 it takes me back, as it is expected (the line with self.finish). Now if i want to go to form2 again it crashes and gets out of the application. ---------------------------------------------------------------------- dseligo · 2025-11-26 22:54 Quote from: mirce.vladimirov on November 26, 2025, 03:42:07 pmand then when I call AndroidModule2 : 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 then     gApp.CreateForm(TAndroidModule2, AndroidModule2);  AndroidModule2.MoveTaskToFront();  AndroidModule2.BackgroundColor:=colbrWhite;  AndroidModule2.InitShowing;  I do it 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   If AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.BackgroundColor := colbrWhite;    // AndroidModule2.DoJNIPromptOnInit := False;    AndroidModule2.Init;  end  else    If AndroidModule2.FormIndex = -1 then      AndroidModule2.ReInit;   AndroidModule2.Show; QuoteFrom that one , i want to go back, exti from AndroidMdule2 to AndroidModule1 : 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  self.Finish;end; I think you just need to use 'Close' instead of 'Finish'. 'Finish' frees form but doesn't set variable AndroidModule2 to nil. Because of that, when you want to show your form, you don't create it again and thus an exception occurs. ---------------------------------------------------------------------- mirce.vladimirov · 2025-11-27 08:40 I copied your advice, now it goes back to Form1 but not goes into Form2 again. Does not crash but just wont go to Form2 again. I tried to use self.close but with that it crashes. On the other hand, self.finish goes back to Form1 but cant return to Form2 again.  I need to go back and forth, from Form2 call Form3... and ocasionaly, just execute a procedure or function from a form and not show it. Quote from: dseligo on November 26, 2025, 11:54:01 pmQuote from: mirce.vladimirov on November 26, 2025, 03:42:07 pmand then when I call AndroidModule2 : 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 then     gApp.CreateForm(TAndroidModule2, AndroidModule2);  AndroidModule2.MoveTaskToFront();  AndroidModule2.BackgroundColor:=colbrWhite;  AndroidModule2.InitShowing;  I do it 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   If AndroidModule2 = nil then  begin    gApp.CreateForm(TAndroidModule2, AndroidModule2);    AndroidModule2.BackgroundColor := colbrWhite;    // AndroidModule2.DoJNIPromptOnInit := False;    AndroidModule2.Init;  end  else    If AndroidModule2.FormIndex = -1 then      AndroidModule2.ReInit;   AndroidModule2.Show; QuoteFrom that one , i want to go back, exti from AndroidMdule2 to AndroidModule1 : 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  self.Finish;end; I think you just need to use 'Close' instead of 'Finish'. 'Finish' frees form but doesn't set variable AndroidModule2 to nil. Because of that, when you want to show your form, you don't create it again and thus an exception occurs. ---------------------------------------------------------------------- dseligo · 2025-11-28 00:30 Quote from: mirce.vladimirov on November 27, 2025, 09:40:41 amI copied your advice, now it goes back to Form1 but not goes into Form2 again. Does not crash but just wont go to Form2 again. I tried to use self.close but with that it crashes. On the other hand, self.finish goes back to Form1 but cant return to Form2 again.  I need to go back and forth, from Form2 call Form3... and ocasionaly, just execute a procedure or function from a form and not show it. I created test app with 3 forms. On each form there are buttons to show other two forms and 'Close' button to close form. I tested it and it works on my phone (Samsung Galaxy S23). I attached this example. P.S.: Other two forms are created at start and they are not freed while app is active, so it is safe to call methods in their classes at any time.