Recent

Author Topic: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components  (Read 5003 times)

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Im trying to create a package for lawm with custom control, derived from jpanel.
It looks that everything is ok untill i try to launch.
I think It may be because of mode, not sure.
Default mode: {$mode objfpc}{$H+}
think i not rigth.
I have seen all the time mode selected i delphi in LAMW units.
But choosing delphi mode throws error registering component.
Any one knows where is the trick?
thanks
« Last Edit: December 26, 2017, 09:29:06 pm by amartitegui »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM: create own package with derived components
« Reply #1 on: December 26, 2017, 07:51:43 pm »
Good initiative!

1) Delphi mode is ok ...  for component code!

2) Put the register procedure in a separate unit ...   example:

Code: Pascal  [Select][+][-]
  1. unit register_mypanels;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7.  
  8. uses
  9.   Classes,
  10.   Laz_And_Controls,
  11.   SysUtils,
  12.   LResources,  //LCLBase dependency/requeriment
  13.   maypanel;
  14.  
  15. Procedure Register;
  16.  
  17. implementation
  18.  
  19. Procedure Register;
  20. begin
  21.   {$I jmypanel_icon.lrs}
  22.   RegisterComponents('Android Bridges MyPanel',[jMyPanel]);
  23. end;
  24.  
  25. end.
  26.  
« Last Edit: December 26, 2017, 07:55:15 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM: create own package with derived components
« Reply #2 on: December 26, 2017, 08:23:31 pm »
Cool man.
And last question about this.
Whats wrong with (because it does not how anything):
Code: Pascal  [Select][+][-]
  1. m_e_d_fecha:=jTextView.Create(jPanel1);
  2.   m_e_d_fecha.Parent:=jPanel1;
  3.   m_e_d_fecha.Enabled := True;
  4.   m_e_d_fecha.Visible := True;
  5.   label_1:=jTextView.Create(jPanel1);
  6.   label_1.Parent:=jPanel1;
  7.   label_1.Enabled := True;
  8.   label_1.Visible := True;
  9.   boton_tricol:=jButton.Create(jPanel1);
  10.   boton_tricol.Parent:=jPanel1;
  11.   boton_tricol.Enabled := True;
  12.   boton_tricol.Visible := True;
  13.   ShowMessage(IntToStr(m_e_d_fecha.Id));
  14.   estado_boton:=0;
  15.   label_1.Text:='proceso';
  16.   boton_tricol.Text:=' ';
  17.   m_e_d_fecha.Text:='00/00/0000';
  18.   boton_tricol.PosRelativeToParent:=[rpLeft];
  19.   boton_tricol.LayoutParamHeight:=lpMatchParent;
  20.   boton_tricol.LayoutParamWidth:=lp24px;
  21.   boton_tricol.BackgroundColor:=colbrRed;
  22.   label_1.Anchor:=boton_tricol;
  23.   label_1.PosRelativeToAnchor:=[raToRightOf,raAlignBaseline];
  24.   m_e_d_fecha.Anchor:=label_1;
  25.   m_e_d_fecha.PosRelativeToAnchor:=[raToRightOf,raAlignBaseline];
  26.   boton_tricol.Visible:=true;
  27.   label_1.Visible:=true;
  28.   m_e_d_fecha.Visible:=true;
  29.   boton_tricol.UpdateLayout();
  30.   label_1.UpdateLayout;
  31.   m_e_d_fecha.UpdateLayout;
  32.   jPanel1.UpdateLayout;

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM: create own package with derived components
« Reply #3 on: December 26, 2017, 09:01:12 pm »
SOLVED. Sorry.
found the :
label_1.Init(gApp);
  boton_tricol.Init(gApp);
  m_e_d_fecha.Init(gApp); 

missing.
Thank pal

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #4 on: December 26, 2017, 09:33:28 pm »
My Suggestion:

Code: Pascal  [Select][+][-]
  1.   myTextView:= jTextView.Create(Self);
  2.   myTextView.Parent:= Self.jPanel1;  
  3.   myTextView.Init(gApp);
  4.   myTextView.Text:= 'Hello!';
  5.   ...................
  6.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #5 on: December 26, 2017, 09:36:01 pm »
In the image You can see that my cutom component shows at dessign time.
public declaration:
  constructor Create(TheOwner:Tcomponent);override;
   destructor destroy;override;
   procedure init(refApp:jApp); if set override, crashes

at component.create:

ProcessView.Create(TheOwner: Tcomponent);
I deffine the components inside panel, and relations.
Then at:
procedure ProcessView.init(refApp: jApp);
begin
  self.init(refApp);
  label_1.Init(refApp);
  boton_tricol.Init(refApp);
  m_e_d_fecha.Init(refApp);
  boton_tricol.UpdateLayout();
  label_1.UpdateLayout;
  m_e_d_fecha.UpdateLayout;
end;

If I use the component it is showed at form dessigner.
But when executing...
Does not show
ideas?
thanks

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #6 on: December 26, 2017, 09:51:45 pm »

Well,  what about "simple thing first" development model?

example:

A new jPanel compound with a simple jTextView ... etc...
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #7 on: December 26, 2017, 11:01:47 pm »
Code: "captionpanel.pas"

Code: Pascal  [Select][+][-]
  1. unit captionpanel;
  2.  
  3. {$mode delphi}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, And_jni, And_jni_Bridge, AndroidWidget, Laz_And_Controls;
  9.  
  10. type
  11.  
  12.   { jCaptionPanel }
  13.  
  14.   jCaptionPanel = class(jPanel)
  15.   private
  16.      FCaption: jTextView;
  17.      procedure CreateTextView(AOwner: TComponent);
  18.   protected
  19.     procedure Loaded; override;
  20.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  21.   public
  22.      constructor Create(AOwner: TComponent); override;
  23.   published
  24.  
  25.   end;
  26.  
  27. implementation
  28.  
  29. { jCaptionPanel }
  30.  
  31.  
  32. //ref. https://groups.google.com/forum/#!topic/borland.public.delphi.objectpascal/SDLCJB350b8
  33.  
  34. constructor jCaptionPanel.Create(AOwner: TComponent);
  35. begin
  36.   inherited;
  37.   FCaption := nil;
  38.   if (csDesigning in ComponentState) then
  39.   begin
  40.      if not (csReading in AOwner.ComponentState) then //this is true when the component is dropped on the form
  41.      begin
  42.         CreateTextView(AOwner);
  43.      end;
  44.   end;
  45. end;
  46.  
  47. procedure jCaptionPanel.CreateTextView(AOwner: TComponent);
  48. begin
  49.    FCaption:= jTextView.Create(AOwner);
  50.    FCaption.Parent:= Self;
  51.    FCaption.Name:= 'jTextViewCaption'; //giving the field FCaption a "variable" name
  52. end;
  53.  
  54.  
  55. procedure jCaptionPanel.Loaded;
  56. var i: Integer;
  57. begin
  58.   inherited;
  59.   for i := 0 to ChildCount - 1 do
  60.   begin
  61.     if Children[i].Name = 'jTextViewCaption' then
  62.     begin
  63.       FCaption:= jTextView(Children[i]); //make FCaption point to the right control
  64.       break;
  65.     end;
  66.   end;
  67.  
  68.   //if the user removes it at design time.....
  69.   if not assigned(FCaption) then
  70.   begin
  71.      if csDesigning in ComponentState then
  72.      begin
  73.        CreateTextView(Owner); //recreate it
  74.      end;
  75.   end;
  76.  
  77. end;
  78.  
  79. procedure jCaptionPanel.Notification(AComponent: TComponent; Operation: TOperation);
  80. begin
  81.   inherited;
  82.   if not (csDestroying in ComponentState) then
  83.   begin
  84.     if operation = opRemove then
  85.     begin
  86.        if AComponent.Name= 'jTextViewCaption' then //if someone removes the component jTextViewCaption ...
  87.        begin
  88.          FCaption:= nil; //prevent AVs until Loaded recreates it the next time the dfm is being loaded
  89.       end;
  90.     end;
  91.   end;
  92. end;
  93.  
  94.  
  95. end.
  96.  

code: "register_customcaptionpanel.pas"

Code: Pascal  [Select][+][-]
  1. unit register_customcaptionpanel;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes,
  9.   captionpanel,
  10.   SysUtils,
  11.   LResources;
  12.  
  13. Procedure Register;
  14.  
  15. implementation
  16.  
  17. Procedure Register;
  18. begin                
  19.   {$I jcaptionpanel_icon.lrs}
  20.   RegisterComponents('Android Bridges Compound',
  21.     [
  22.       jCaptionPanel
  23.     ]
  24.   );
  25. end;
  26.  
  27. end.
  28.  

res: "jcaptionpanel_icon.lrs"  [Attachment]

Warning:

1) Only Experimental/Explore code....
2) [LAMW] form designer do not support [perfectly] component composition....
« Last Edit: January 03, 2018, 12:02:00 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #8 on: December 27, 2017, 07:43:45 pm »
uffff...
Driving me crazy, man.
It works... almost but not yet.
this gives me an app crash:
procedure jCaptionPanel.Init(refApp: jApp);
begin
  inherited Init(refApp);
  FMyCaption.Init(refApp);
end;
Without it dont crash app. It shows ok at dessign. but does not show in app.
mmmmmmmm
something tricky.
When doing with a little more complex .... same thing.
It shows fine at dessign time, but when running app it shows nothing.
and if inheriting init app crash...
Im lost... dont know why.

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #9 on: December 27, 2017, 07:50:06 pm »
Another thing I've seen.
At dessign time, it u set the layoutparamwith to match parent for example, it does not execute as it does a jpanel.
I could do this using a panel and build the components and then copy paste.... but I wanted to see how it works .... or at least if it works like desktop aproach.

I think It can be useful to build some custom components.

But there is something im not getting, and dont know what. looks close...

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #10 on: December 27, 2017, 08:55:29 pm »
Remember:
Quote
[LAMW] form designer do not support [perfectly] component composition....

Go to your project java folder ".....src\...\....\"   .... can you see  some "jPanel.java" ???
[if you have any/other jPanel in your form designer, yes! Else, you need put some there!
.... copy from LAMW folder "......java\lamwdesigner",  but change the first line to your package name!]


We still need a lot of work so the LAMW wizard can work with composition of components!
« Last Edit: December 27, 2017, 09:04:32 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #11 on: December 27, 2017, 09:03:19 pm »
Ok man. Will try a little later. Thanks

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #12 on: January 03, 2018, 12:15:44 am »
Hello  amartitegui!

Now we can do component composition! 

1. The "captionpanel.pas"  above was fixed/updated...

2. Update  "SmartDesigner.pas" from github ...

3.  Create the helper file:   

"jCaptionPanel.compound"   with this content  [two lines]:
Quote
jPanel
jTextView

and save to LAMW folder "......\java\lamwdesigner"

4. Install the package  and test!

Thank you!

P.S  You can try add your component to "lamwdesigner.pas" ....  so, you will get a improved
designer  support  [look for "DraftPanel/jPanel" code and try mimic it...]
« Last Edit: January 03, 2018, 01:52:15 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

amartitegui

  • Jr. Member
  • **
  • Posts: 84
Re: LAWM:(ALMOST SOLVED...BUT...) create own package with derived components
« Reply #13 on: January 22, 2018, 09:08:07 pm »
Uuuups didnt seen it.
Great man. Will try.
Been working on other parts of oroject(computer side) and ive been a little out of the android part.
Thanks

 

TinyPortal © 2005-2018