LAMW new jForm creation cycle lazarus / 43-Android ---------------------------------------------------------------------- jmpessoa · 2019-08-08 23:30 Hi All, With the intention of enabling the creation of hidden  [actRecyclable]  LAMW "jForms" .... the creation/init/show of the jForm cycle  has changed!!!   [a patch by @TR3E] ["Init/ReInit"  will no longer [automatically] "show"  a [actRecyclable]  jForm.... sorry] The cycle of [actRecyclable] "jForms" change to: Quote1) "Create" -> "Init" -> "Show"      or  Quote2) "Create" -> "Init"        //hidden jForm...   So,  we can code: 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.AndroidModule1JNIPrompt(Sender: TObject);begin  if AndroidModule2 = nil then   begin      gApp.CreateForm(TAndroidModule2, AndroidModule2);      //AndroidModule2.DoJNIPromptOnInit:= False; //not fire "OnJNIPrompt"    AndroidModule2.Init(gApp);    //by default call OnJNIPrompt in form2     end;     //"Init"  will no longer "show"  [automatically]  the form .... sorry   end;  and later: 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.jButton1Click(Sender: TObject);begin  if AndroidModule2 <> nil then  begin      //AndroidModule2.DoJNIPromptOnShow:= False; //not fire "OnJNIPrompt"    AndroidModule2.Show(); //by default call OnJNIPrompt in form2,  too!  end;end;  I hope this change does not cause much trouble ....  Yes! Some old code can be easily fixed: [considering that "Init"  no longer show the form....] Code: [Select]procedure TAndroidModule1.jButton1Click(Sender: TObject); begin   if AndroidModule2 = nil then   begin     gApp.CreateForm(TAndroidModule2, AndroidModule2);     AndroidModule2.InitShowing(gApp); // <-- Fixed!!!   end   else   begin     AndroidModule2.Show();   end; end; PS. In case of doubt ... the demos for the multi-forms Apps are "up to date"!   [Thanks to @TR3E!]       example: "..../demos/GUI/AppTest1" ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2019-08-09 02:19 Why the Init doesn't trigger automatically by OnCreate event? I think it makes full of confusion for a standard LCL user, I'm not sure in Android Studio we should do this. Why is necessary to use that event? So, if actRecyclable will not show the form, what the usage of actEasel? We only need to use actRecycleable too rather than actEasel to make dummy components as a child, aren't we? Sorry for my curiosity. ---------------------------------------------------------------------- jmpessoa · 2019-08-09 03:40 QuoteWhy the Init doesn't trigger automatically by OnCreate event? "OnCreate"  is a Pascal side event [java knows nothing about pascal side  "OnCreate" ....] "Init"  is the first interaction between Pascal code and Java code .... After "Init" You can talk to java/JNI  via/handling   "OnJNIPrompt" Quoteif actRecyclable will not show the form... No!!  The only change is that now you need call "Show()"  after "Init/ReInit" [or use "InitShowing(gApp)"  to Fix old code!] QuoteWe only need to use actRecycleable too rather than actEasel to make dummy components as a child, aren't we? No!! you can keep using  actRecycleable and actEasel  in the same way ... The impacting change is that now actRecycleable need "Show()" after "Init/ReInit".... [but you can use "InitShowing(gApp)"  to replace  "Init(gApp)"  in some  old code!] ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2019-08-09 09:47 Quote from: jmpessoa on August 09, 2019, 05:40:05 amQuoteWhy the Init doesn't trigger automatically by OnCreate event? "OnCreate"  is a Pascal side event [java knows nothing about pascal side  "OnCreate" ....] "Init"  is the first interaction between Pascal code and Java code .... After "Init" You can talk to java/JNI  via/handling   "OnJNIPrompt" But, why I modified LAMW's unit in the AndroidWidget like this is still working? Is this will cause a catastrophic error in the future? Option 1 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 jApp.CreateForm(InstanceClass: TComponentClass; out Reference);var  Instance: TComponent;begin  Instance := TComponent(InstanceClass.NewInstance);  TComponent(Reference):= Instance;  Instance.Create(Self);  // this thing, it just works.  jForm(Instance).Init(Self);end;   Not just that, we can do this one too. Option 2 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 constructor jForm.Create(AOwner: TComponent);begin  CreateNew(AOwner); //no stream loaded yet. {thanks to  x2nie !!}   FVisible              := False; //true just after Show!  FEnabled              := True;  FColor              := colbrDefault;  FormState             := fsFormCreate;  FCloseCallBack.Event  := nil;  FCloseCallBack.EventData:= nil;  FCloseCallBack.EventPointer:= nil;  FCloseCallBack.Sender := nil;  FActivityMode         := ActivityModeDesign; //actMain;  //actMain, actRecyclable, actSplash, act...   FActionBarTitle:= abtDefault;   FOnCloseQuery         := nil;  FOnClose              := nil;  FOnRotate             := nil;  FOnClick              := nil;  FOnActivityRst        := nil;  FOnJNIPrompt          := nil;  FOnSpecialKeyDown     := nil;   FjObject              := nil;  FjRLayout{View}       := nil;   FScreenWH.Height      := 100; //dummy  FScreenWH.Width       := 100;   FAnimation.In_        := cjEft_None; //cjEft_FadeIn;  FAnimation.Out_       := cjEft_None; //cjEft_FadeOut;  FScreenStyle          := ssUnknown;  FInitialized        := False;   FMarginBottom:= 0;  FMarginLeft:= 0;  FMarginRight:= 0;  FMarginTop:= 0;   FWidth := 320;  FHeight := 400;  Finished:= False;   FormBaseIndex:= -1;  //dummy - main form not have a form base  FormIndex:= -1;      //dummy   PromptOnBackKey:= True;  TryBacktrackOnClose:= False;   DoJNIPromptOnShow:= True;      //now load the stream  InitInheritedComponent(Self, TAndroidWidget {TAndroidForm}); {thanks to  x2nie !!}  // this thing, it just works.  Init(jApp(AOwner));end; And, the last... We can do a thing like this onCreate. 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.AndroidModule2Create(Sender: TObject);begin  //Self.Init(gApp);  jButton1.BackgroundColor := colbrMaroon;  ShowMessage('It just works!');end; And... Hola! On attachment. ---------------------------------------------------------------------- jmpessoa · 2019-08-09 19:27 Nice insight! Quotethis will cause a catastrophic error in the future? ... Test, test,  and  test.... only many tests can answer us .... But, we will try! Thank you! ---------------------------------------------------------------------- AFFRIZA 亜風実 · 2019-08-10 07:08 Quote from: jmpessoa on August 09, 2019, 09:27:55 pmNice insight! Thank you  QuoteTest, test,  and  test.... only many tests can answer us .... But, we will try! Thank you! That's very small that I can try for now than what I wish for, hehe... I hope error handling become handy in the future of LAMW. I think there are many hidden things need to be discovered. ---------------------------------------------------------------------- jmpessoa · 2019-08-10 22:24 Just as reinforcement: Considering that "Init"  no longer show the form....Some old code can be easily fixed: example: Code: [Select]procedure TAndroidModule1.jButton1Click(Sender: TObject); begin   if AndroidModule2 = nil then   begin     gApp.CreateForm(TAndroidModule2, AndroidModule2);     AndroidModule2.InitShowing(gApp);                             // <-- Fixed!!!   end   else   begin     AndroidModule2.Show();   end; end;