LAWM:(ALMOST SOLVED...BUT...) create own package with derived components lazarus / 43-Android ---------------------------------------------------------------------- amartitegui · 2017-12-26 18:32 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 ---------------------------------------------------------------------- jmpessoa · 2017-12-26 18:51 Good initiative! 1) Delphi mode is ok ...  for component code! 2) Put the register procedure in a separate unit ...   example: 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 unit register_mypanels;  {$mode objfpc}{$H+}  interface  uses   Classes,  Laz_And_Controls,   SysUtils,  LResources,  //LCLBase dependency/requeriment  maypanel;  Procedure Register;  implementation  Procedure Register;begin  {$I jmypanel_icon.lrs}  RegisterComponents('Android Bridges MyPanel',[jMyPanel]);end;  end. ---------------------------------------------------------------------- amartitegui · 2017-12-26 19:23 Cool man. And last question about this. Whats wrong with (because it does not how anything): 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 m_e_d_fecha:=jTextView.Create(jPanel1);  m_e_d_fecha.Parent:=jPanel1;  m_e_d_fecha.Enabled := True;  m_e_d_fecha.Visible := True;  label_1:=jTextView.Create(jPanel1);  label_1.Parent:=jPanel1;  label_1.Enabled := True;  label_1.Visible := True;  boton_tricol:=jButton.Create(jPanel1);  boton_tricol.Parent:=jPanel1;  boton_tricol.Enabled := True;  boton_tricol.Visible := True;  ShowMessage(IntToStr(m_e_d_fecha.Id));  estado_boton:=0;  label_1.Text:='proceso';  boton_tricol.Text:=' ';  m_e_d_fecha.Text:='00/00/0000';  boton_tricol.PosRelativeToParent:=[rpLeft];  boton_tricol.LayoutParamHeight:=lpMatchParent;  boton_tricol.LayoutParamWidth:=lp24px;  boton_tricol.BackgroundColor:=colbrRed;  label_1.Anchor:=boton_tricol;  label_1.PosRelativeToAnchor:=[raToRightOf,raAlignBaseline];  m_e_d_fecha.Anchor:=label_1;  m_e_d_fecha.PosRelativeToAnchor:=[raToRightOf,raAlignBaseline];  boton_tricol.Visible:=true;  label_1.Visible:=true;  m_e_d_fecha.Visible:=true;  boton_tricol.UpdateLayout();  label_1.UpdateLayout;  m_e_d_fecha.UpdateLayout;  jPanel1.UpdateLayout; ---------------------------------------------------------------------- amartitegui · 2017-12-26 20:01 SOLVED. Sorry. found the : label_1.Init(gApp);   boton_tricol.Init(gApp);   m_e_d_fecha.Init(gApp);  missing. Thank pal ---------------------------------------------------------------------- jmpessoa · 2017-12-26 20:33 My Suggestion: 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   myTextView:= jTextView.Create(Self);  myTextView.Parent:= Self.jPanel1;    myTextView.Init(gApp);  myTextView.Text:= 'Hello!';  ................... ---------------------------------------------------------------------- amartitegui · 2017-12-26 20:36 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 · 2017-12-26 20:51 Well,  what about "simple thing first" development model? example: A new jPanel compound with a simple jTextView ... etc... ---------------------------------------------------------------------- jmpessoa · 2017-12-26 22:01 Code: "captionpanel.pas" 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 unit captionpanel; {$mode delphi} interface uses  Classes, SysUtils, And_jni, And_jni_Bridge, AndroidWidget, Laz_And_Controls; type   { jCaptionPanel }   jCaptionPanel = class(jPanel)  private     FCaption: jTextView;     procedure CreateTextView(AOwner: TComponent);  protected    procedure Loaded; override;    procedure Notification(AComponent: TComponent; Operation: TOperation); override;  public     constructor Create(AOwner: TComponent); override;  published   end; implementation { jCaptionPanel }  //ref. h ttps://groups.google.com/forum/#!topic/borland.public.delphi.objectpas cal/SDLCJB350b8 constructor jCaptionPanel.Create(AOwner: TComponent);begin  inherited;  FCaption := nil;  if (csDesigning in ComponentState) then  begin     if not (csReading in AOwner.ComponentState) then //this is true when the component is dropped on the form     begin        CreateTextView(AOwner);     end;  end;end; procedure jCaptionPanel.CreateTextView(AOwner: TComponent);begin   FCaption:= jTextView.Create(AOwner);   FCaption.Parent:= Self;   FCaption.Name:= 'jTextViewCaption'; //giving the field FCaption a "variable" nameend;  procedure jCaptionPanel.Loaded;var i: Integer;begin  inherited;  for i := 0 to ChildCount - 1 do  begin    if Children[i].Name = 'jTextViewCaption' then    begin      FCaption:= jTextView(Children[i]); //make FCaption point to the right control      break;    end;  end;   //if the user removes it at design time.....  if not assigned(FCaption) then  begin     if csDesigning in ComponentState then     begin       CreateTextView(Owner); //recreate it     end;  end; end; procedure jCaptionPanel.Notification(AComponent: TComponent; Operation: TOperation);begin  inherited;  if not (csDestroying in ComponentState) then  begin    if operation = opRemove then    begin       if AComponent.Name= 'jTextViewCaption' then //if someone removes the component jTextViewCaption ...       begin         FCaption:= nil; //prevent AVs until Loaded recreates it the next time the dfm is being loaded      end;    end;  end;end;  end.  code: "register_customcaptionpanel.pas" 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 unit register_customcaptionpanel;  {$mode objfpc}{$H+}  interface  uses  Classes,  captionpanel,  SysUtils,  LResources;  Procedure Register;  implementation  Procedure Register;begin                   {$I jcaptionpanel_icon.lrs}  RegisterComponents('Android Bridges Compound',    [      jCaptionPanel    ]  );end;  end.  res: "jcaptionpanel_icon.lrs"  [Attachment] Warning: 1) Only Experimental/Explore code.... 2) [LAMW] form designer do not support [perfectly] component composition.... ---------------------------------------------------------------------- amartitegui · 2017-12-27 18:43 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 · 2017-12-27 18:50 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 · 2017-12-27 19:55 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! ---------------------------------------------------------------------- amartitegui · 2017-12-27 20:03 Ok man. Will try a little later. Thanks ---------------------------------------------------------------------- jmpessoa · 2018-01-02 23:15 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]: QuotejPanel 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...] ---------------------------------------------------------------------- amartitegui · 2018-01-22 20:08 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