Recent

Author Topic: LAMW new jForm creation cycle  (Read 350 times)

jmpessoa

  • Hero Member
  • *****
  • Posts: 1401
LAMW new jForm creation cycle
« on: August 09, 2019, 01:30:51 am »
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:

Quote
1) "Create" -> "Init" -> "Show"     

or 

Quote
2) "Create" -> "Init"        //hidden jForm...

 
So,  we can code:

Code: Pascal  [Select]
  1. procedure TAndroidModule1.AndroidModule1JNIPrompt(Sender: TObject);
  2. begin
  3.   if AndroidModule2 = nil then
  4.   begin
  5.       gApp.CreateForm(TAndroidModule2, AndroidModule2);
  6.       //AndroidModule2.DoJNIPromptOnInit:= False; //not fire "OnJNIPrompt"
  7.       AndroidModule2.Init(gApp);    //by default call OnJNIPrompt in form2  
  8.   end;  
  9.  
  10.   //"Init"  will no longer "show"  [automatically]  the form .... sorry
  11.    
  12. end;
  13.  

and later:

Code: Pascal  [Select]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.   if AndroidModule2 <> nil then
  4.   begin
  5.       //AndroidModule2.DoJNIPromptOnShow:= False; //not fire "OnJNIPrompt"
  6.       AndroidModule2.Show(); //by default call OnJNIPrompt in form2,  too!
  7.   end;
  8. end;
  9.  

I hope this change does not cause much trouble ....  O:-) O:-)


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"   
« Last Edit: August 11, 2019, 12:29:01 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Dio Affriza

  • New member
  • *
  • Posts: 49
Re: LAMW new jForm creation cycle
« Reply #1 on: August 09, 2019, 04:19:37 am »
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.  :D

jmpessoa

  • Hero Member
  • *****
  • Posts: 1401
Re: LAMW new jForm creation cycle
« Reply #2 on: August 09, 2019, 05:40:05 am »
Quote
Why 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"


Quote
if 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!]

Quote
We 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!]
« Last Edit: August 11, 2019, 12:19:48 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Dio Affriza

  • New member
  • *
  • Posts: 49
Re: LAMW new jForm creation cycle
« Reply #3 on: August 09, 2019, 11:47:08 am »
Quote
Why 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]
  1. procedure jApp.CreateForm(InstanceClass: TComponentClass; out Reference);
  2. var
  3.   Instance: TComponent;
  4. begin
  5.   Instance := TComponent(InstanceClass.NewInstance);
  6.   TComponent(Reference):= Instance;
  7.   Instance.Create(Self);
  8.   // this thing, it just works.
  9.   jForm(Instance).Init(Self);
  10. end;    
  11.  

Not just that, we can do this one too.
Option 2
Code: Pascal  [Select]
  1. constructor jForm.Create(AOwner: TComponent);
  2. begin
  3.   CreateNew(AOwner); //no stream loaded yet. {thanks to  x2nie !!}
  4.  
  5.   FVisible              := False; //true just after Show!
  6.   FEnabled              := True;
  7.   FColor                := colbrDefault;
  8.   FormState             := fsFormCreate;
  9.   FCloseCallBack.Event  := nil;
  10.   FCloseCallBack.EventData:= nil;
  11.   FCloseCallBack.EventPointer:= nil;
  12.   FCloseCallBack.Sender := nil;
  13.   FActivityMode         := ActivityModeDesign; //actMain;  //actMain, actRecyclable, actSplash, act...
  14.  
  15.   FActionBarTitle:= abtDefault;
  16.  
  17.   FOnCloseQuery         := nil;
  18.   FOnClose              := nil;
  19.   FOnRotate             := nil;
  20.   FOnClick              := nil;
  21.   FOnActivityRst        := nil;
  22.   FOnJNIPrompt          := nil;
  23.   FOnSpecialKeyDown     := nil;
  24.  
  25.   FjObject              := nil;
  26.   FjRLayout{View}       := nil;
  27.  
  28.   FScreenWH.Height      := 100; //dummy
  29.   FScreenWH.Width       := 100;
  30.  
  31.   FAnimation.In_        := cjEft_None; //cjEft_FadeIn;
  32.   FAnimation.Out_       := cjEft_None; //cjEft_FadeOut;
  33.   FScreenStyle          := ssUnknown;
  34.   FInitialized          := False;
  35.  
  36.   FMarginBottom:= 0;
  37.   FMarginLeft:= 0;
  38.   FMarginRight:= 0;
  39.   FMarginTop:= 0;
  40.  
  41.   FWidth := 320;
  42.   FHeight := 400;
  43.   Finished:= False;
  44.  
  45.   FormBaseIndex:= -1;  //dummy - main form not have a form base
  46.   FormIndex:= -1;      //dummy
  47.  
  48.   PromptOnBackKey:= True;
  49.   TryBacktrackOnClose:= False;
  50.  
  51.   DoJNIPromptOnShow:= True;
  52.  
  53.  
  54.   //now load the stream
  55.   InitInheritedComponent(Self, TAndroidWidget {TAndroidForm}); {thanks to  x2nie !!}
  56.   // this thing, it just works.
  57.   Init(jApp(AOwner));
  58. end;  
  59.  

And, the last... We can do a thing like this onCreate.
Code: Pascal  [Select]
  1. procedure TAndroidModule2.AndroidModule2Create(Sender: TObject);
  2. begin
  3.   //Self.Init(gApp);
  4.   jButton1.BackgroundColor := colbrMaroon;
  5.   ShowMessage('It just works!');
  6. end;  
  7.  

And... Hola! On attachment.
« Last Edit: August 10, 2019, 05:16:50 am by Dio Affriza »

jmpessoa

  • Hero Member
  • *****
  • Posts: 1401
Re: LAMW new jForm creation cycle
« Reply #4 on: August 09, 2019, 09:27:55 pm »

Nice insight!

Quote
this will cause a catastrophic error in the future? ...

Test, test,  and  test....
only many tests can answer us ....

But, we will try!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Dio Affriza

  • New member
  • *
  • Posts: 49
Re: LAMW new jForm creation cycle
« Reply #5 on: August 10, 2019, 09:08:03 am »
Nice insight!
Thank you  :D

Quote
Test, 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

  • Hero Member
  • *****
  • Posts: 1401
Re: LAMW new jForm creation cycle
« Reply #6 on: August 11, 2019, 12:24:43 am »
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;
« Last Edit: August 11, 2019, 12:26:39 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard