web widgetset Components to code lazarus / 31-LCL ---------------------------------------------------------------------- warleyalex · 2018-03-02 21:30 It is on the oven a tool named TMS Web Core that actually use the Delphi XE7 and its form designer to create web applications. You Just drop components onto a form and set up at the objector inspector, the events and the properties. All of the above is great and it will no doubt give us the same benefits as Delphi/Lazarus developers currently enjoy. The pas2js compiler will auto generate the components for you. It has been said in Delphi it works absolutely splendid. I was recently analyzing the generated code of the so called TMS Web Core framework, and and quite a bit of effort, doing some reverve engineering I believe I created a clone! Since Delphi/Lazarus comes with a bunch of ready to use UI elements and widgets like modals, popups, popover, searchbar, side panels, headerBar, jsut been thinking to create lightweight kind of "fake" web widgets to be used into the Lazarus designer. Michael Van Canneyt has suggested: "All you need to do is create a web-widgetset for the LCL."  I've spent a few minutes reflecting on this, what's the hack is widgetset for the LCL? I've been using Lazarus less than one month. Anyway, using Package/New Package... I've created some visual web "dummy" components (TWebLabel, TWEBEdit, TWebButton, TWebComboBox and TWebMemo) all those components inherits from the TCustomControl. The idea would be drag'n drop the components on the form. After all, the main form unit looks 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 unit Unit1;  {$mode objfpc}{$H+}  interface  uses   SysUtils, Classes, JS, Web,   WEBLib.Graphics, WEBLIB.Controls, WEBLib.StdCtrls, WEBLib.ExtCtrls,   WEBLib.Forms,  WEBLib.Dialogs;  type   TForm1 = class(TWebForm)   private     { Private declarations }     WebLabel1: TWebLabel;     WebEdit1: TWebEdit;     WebButton1: TWebButton;     WebMemo1: TWebMemo;     WebComboBox1: TWebComboBox;     WebPanel1: TWebPanel;   WebLabel2: TWebLabel;     WebImageControl1: TWebImage;   public     { Public declarations }     procedure LoadDFMValues; override;     procedure WebButton1Click(Sender: TObject);     procedure WebComboBox1Change(Sender: TObject);   end;  var   Form1: TForm1;  implementation  {$R *.lfm}  { TForm1 }  procedure TForm1.LoadDFMValues; begin   inherited;   //LoadDFMFromStream('Unit1.dfm');   end;  procedure TForm1.WebButton1Click(Sender: TObject); begin   console.log('button clicked');   WebComboBox1.Items.Add(WebEdit1.Text);   WebComboBox1.ItemIndex := WebComboBox1.Items.Count - 1;   WebMemo1.Lines.Add(WebEdit1.Text); end;  procedure TForm1.WebComboBox1Change(Sender: TObject); begin   WebLabel1.Caption := WebComboBox1.Items[WebComboBox1.GetItemIndex]; end;  end.  It is a little bit different from win32 app. Notice the LoadDFMValues method. TMS Web Core does crazy things such auto generates the LoadDFMValues method.  If you don't know what the hell I'm talking about, in the web application world the DFM/LFM forms are embedded on the javascript, so the method should have such content: procedure TForm1.LoadDFMValues; begin   inherited;   WebLabel1        := TWebLabel.Create(Self);   WebEdit1         := TWebEdit.Create(Self);   WebButton1       := TWebButton.Create(Self);   WebMemo1         := TWebMemo.Create(Self);   WebComboBox1     := TWebComboBox.Create(Self);   WebPanel1        := TWebPanel.Create(Self);   WebLabel2        := TWebLabel.Create(WebPanel1);   WebImageControl1 := TWebImage.Create(WebPanel1);   WebLabel1.BeginUpdate;   WebEdit1.BeginUpdate;   WebButton1.BeginUpdate;   WebMemo1.BeginUpdate;   WebComboBox1.BeginUpdate;   WebPanel1.BeginUpdate;   WebLabel2.BeginUpdate;   WebImageControl1.BeginUpdate;   try     Self.Name           := 'Form1';     Self.Left           := 0;     Self.Top            := 0;     Self.Width          := 640;     Self.Height         := 480;     Self.Font.Charset   := 1;     Self.Font.Color     := 0;     Self.Font.Height    := -13;     Self.Font.Name      := 'Tahoma';     Self.Font.Style     := [fsBold];     Self.FFormContainer := 'appcontent';     Self.TabOrder       := 1;     WebLabel1.Parent  := Self;     WebLabel1.Name    := 'WebLabel1';     WebLabel1.Left    := 64;     WebLabel1.Top     := 232;     WebLabel1.Width   := 40;     WebLabel1.Height  := 16;     WebLabel1.Caption := '-Label-';     WebEdit1.Parent   := Self;     WebEdit1.Name     := 'WebEdit1';     WebEdit1.Left     := 64;     WebEdit1.Top      := 42;     WebEdit1.Width    := 121;     WebEdit1.Height   := 24;     WebEdit1.TabOrder := 0;     WebEdit1.TextHint := 'Add some text ...';     WebButton1.Parent   := Self;     WebButton1.Name     := 'WebButton1';     WebButton1.Left     := 204;     WebButton1.Top      := 40;     WebButton1.Width    := 75;     WebButton1.Height   := 25;     WebButton1.Caption  := 'Add';     WebButton1.OnClick := @WebButton1Click;     WebButton1.TabOrder := 1;     WebMemo1.Parent     := Self;     WebMemo1.Name       := 'WebMemo1';     WebMemo1.Left       := 64;     WebMemo1.Top        := 88;     WebMemo1.Width      := 215;     WebMemo1.Height     := 89;     WebMemo1.AutoSize   := false;     WebMemo1.SelLength  := 0;     WebMemo1.SelStart   := 0;     WebMemo1.TabOrder   := 2;     WebComboBox1.Parent     := Self;     WebComboBox1.Name       := 'WebComboBox1';     WebComboBox1.Left       := 64;     WebComboBox1.Top        := 197;     WebComboBox1.Width      := 215;     WebComboBox1.Height     := 24;     WebComboBox1.ItemIndex  := -1;     WebComboBox1.TabOrder   := 3;     WebComboBox1.Text       := 'WebComboBox1';     WebComboBox1.OnChange  := @WebComboBox1Change;     WebPanel1.Parent      := Self;     WebPanel1.Name        := 'WebPanel1';     WebPanel1.Left        := 64;     WebPanel1.Top         := 272;     WebPanel1.Width       := 513;     WebPanel1.Height      := 89;     WebPanel1.WidthStyle  := TSizeStyle.ssPercent;     WebPanel1.WidthPercent:= 80;     WebPanel1.BorderStyle := TBorderStyle.bsSingle;     WebLabel2.Parent      := WebPanel1;     WebLabel2.Name        := 'WebLabel2';     WebLabel2.Left        := 3;     WebLabel2.Top         := 29;     WebLabel2.Width       := 411;     WebLabel2.Height      := 32;     WebLabel2.Caption     := 'This demo shows the use of basic controls like TWebEdit, TWebButton, TWebComboBox, TWebMemo and TWebLabel.';     WebLabel2.WordWrap   := true;     WebLabel2.WidthStyle  := TSizeStyle.ssPercent;     WebImageControl1.Parent    := WebPanel1;     WebImageControl1.Name      := 'WebImageControl1';     WebImageControl1.Left      := 6;     WebImageControl1.Top       := 7;     WebImageControl1.Width     := 16;     WebImageControl1.Height    := 16;     WebImageControl1.AutoSize := true;     WebImageControl1.Picture.LoadFromFile('Picture.png');   finally     WebLabel1.EndUpdate;     WebEdit1.EndUpdate;     WebButton1.EndUpdate;     WebMemo1.EndUpdate;     WebComboBox1.EndUpdate;     WebPanel1.EndUpdate;     WebLabel2.EndUpdate;     WebImageControl1.EndUpdate;   end; end; Exactly, they're using kinda magical trick, scan and parse the .DFM then generates the creation code for the current form and its owned components, pretty close to GExpert feature "Components to Code" plugin. Any idea how to implement the "Components to Code" using Lazarus? Regards, warleyalex ---------------------------------------------------------------------- Phil · 2018-03-02 21:57 Quote from: warleyalex on March 02, 2018, 10:30:47 pmAny idea how to implement the "Components to Code" using Lazarus? I think you've already answered the question: Parse the .lfm file and generate the code. IDEs have been doing that for years. ---------------------------------------------------------------------- engkin · 2018-03-03 02:31 Take a look at JsonToObject and ObjectToJson in unit fpjsonrtti. ---------------------------------------------------------------------- warleyalex · 2018-03-05 13:12 The solution is almost 100%-ready! There's a component serialisation into Pascal in the oven but not integrated with the Lazarus IDE yet. ---------------------------------------------------------------------- ttomas · 2018-03-05 14:40 Best solution is to integrate in pas2js compiler. If you look the source in pas2js\compiler\packages\pastojs\src pas2js\compiler\packages\fcl-passrc\src  you can find a lot of interesting code. 1. Parse *.pas and look for {$R *.lfm} resource. 2. Parse lfm 3. Compile pas2js and include/link/??? lfm code in *.js Idea is to have only one *.pas file. ---------------------------------------------------------------------- warleyalex · 2018-03-05 22:50 LFM/DFM-serialization mechanism which Lazarus/Delphi ships with may be pretty useful. Let's start from the simple example. As you can see LFM-format is pretty straightforward. 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 object Form1: TForm1  Left = 350  Height = 480  Hint = 'Form1'  Top = 0  Width = 640  Caption = 'Form1'  ClientHeight = 480  ClientWidth = 640  LCLVersion = '1.9.0.0'  object WebLabel1: TLabel    Left = 64    Height = 13    Top = 232    Width = 33    Caption = '-Label-'    ParentColor = False  end  object WebEdit1: TEdit    Left = 64    Height = 21    Top = 42    Width = 121    ParentShowHint = False    ShowHint = True    TabOrder = 0    Text = 'WebEdit1'    TextHint = 'Add some text ...'  end  object WebButton1: TButton    Left = 204    Height = 25    Top = 40    Width = 75    Caption = 'Add'    OnClick = WebButton1Click    TabOrder = 1  end  object WebMemo1: TMemo    Left = 64    Height = 145    Top = 89    Width = 215    Lines.Strings = (    'WebMemo1'    )    TabOrder = 2  end  object WebComboBox1: TComboBox    Left = 64    Height = 21    Top = 197    Width = 215    ItemHeight = 13    OnChange = WebComboBox1Change    TabOrder = 3    Text = 'WebComboBox1'  end  object WebPanel1: TPanel    Left = 64    Height = 89    Top = 280    Width = 513    ClientHeight = 89    ClientWidth = 513    TabOrder = 4    object WebLabel2: TLabel      Left = 3      Height = 32      Top = 29      Width = 411      AutoSize = False      Caption = 'This demo shows the use of basic controls like TWebEdit, TWebButton, TWebComboBox, TWebMemo and TWebLabel.'      ParentColor = False      WordWrap = True    end    object WebImageControl1: TImage    Left = 6      Height = 16      Top = 7      Width = 16      AutoSize = True    end  end  object Btn: TButton    Left = 64    Height = 33    Top = 384    Width = 95    Caption = 'Btn'    OnClick = BtnClick    TabOrder = 5  endend I have modified the pascalstream example to include the BeginUpdade..EndUpdate block and we serialise the form into Pascal: 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 WebLabel1:= TLabel.Create(Self);WebEdit1:=TEdit.Create(Self);WebButton1:=TButton.C reate(Self);WebMemo1:=TMemo.Create(Self);WebComboBox1:=TComboBox.Creat e(Self);WebPanel1:=TPanel.Create(Self);WebLabel2:=TLabel.Create(Self); WebImageControl1:=TImage.Create(Self);Btn:=TButton.Create(Self); WebLa bel1.BeginUpdate;WebEdit1.BeginUpdate;WebButton1.BeginUpdate;WebMemo1. BeginUpdate;WebComboBox1.BeginUpdate;WebPanel1.BeginUpdate;WebLabel2.B eginUpdate;WebImageControl1.BeginUpdate;Btn.BeginUpdate;try  Name:='Form1';  Left:=350;  Height:=480;  Top:=0;  Width:=640;  Caption:='Form1';  ClientHeight:=480;  ClientWidth:=640;  LCLVersion:='1.9.0.0';  with WebLabel1 do begin    Name:='WebLabel1';    Left:=64;    Height:=13;    Top:=232;    Width:=33;    Caption:='-Label-';    ParentColor:=False;    TPasStreamAccess(TComponent(WebLabel1)).SetParentComponent(Self);  end;  with WebEdit1 do begin    Name:='WebEdit1';    Left:=64;    Height:=21;    Top:=42;    Width:=121;    ParentShowHint:=False;    ShowHint:=True;    TabOrder:=0;    Text:='WebEdit1';    TextHint:='Add some text ...';    TPasStreamAccess(TComponent(WebEdit1)).SetParentComponent(Self);  end;  with WebButton1 do begin    Name:='WebButton1';    Left:=204;  Height:=25;    Top:=40;    Width:=75;    Caption:='Add';    OnClick:=@WebButton1Click;    TabOrder:=1;    TPasStreamAccess(TComponent(WebButton1)).SetParentComponent(Self);  end;  with WebMemo1 do begin    Name:='WebMemo1';    Left:=64;    Height:=145;    Top:=89;    Width:=215;    ExecCustomCSP(Lines,[#7'Strings'#1#6#8'WebMemo1'#0#0]);    TabOrder:=2;    TPasStreamAccess(TComponent(WebMemo1)).SetParentComponent(Self);  end;  with WebComboBox1 do begin    Name:='WebComboBox1';    Left:=64;    Height:=21;    Top:=197;    Width:=215;    ItemHeight:=13;    OnChange:=@WebComboBox1Change;    TabOrder:=3;    Text:='WebComboBox1';    TPasStreamAccess(TComponent(WebComboBox1)).SetParentComponent(Self);  end;  with WebPanel1 do begin    Name:='WebPanel1';    Left:=64;    Height:=89;    Top:=280;    Width:=513;    ClientHeight:=89;    ClientWidth:=513;    TabOrder:=4;    TPasStreamAccess(TComponent(WebPanel1)).SetParentComponent(Self);    with WebLabel2 do begin      Name:='WebLabel2';      Left:=3;      Height:=32;      Top:=29;      Width:=411;      AutoSize:=False;      Caption:='This demo shows the use of basic controls like TWebEdit, TWebButton, TWebComboBox, TWebMemo and TWebLabel.';      ParentColor:=False;      WordWrap:=True;      TPasStreamAccess(TCompon ent(WebLabel2)).SetParentComponent(WebPanel1);    end;    with WebImageControl1 do begin      Name:='WebImageControl1';      Left:=6;      Height:=16;      Top:=7;      Width:=16;      AutoSize:=True;      TPasStreamAccess(TComponent(WebImageControl1)).Se tParentComponent(WebPanel1);    end;  end;  with Btn do begin    Name:='Btn';    Left:=64;    Height:=33;    Top:=384;    Width:=95;  Caption:='Btn';    OnClick:=@BtnClick;    TabOrder:=5;    TPasStreamAccess(TComponent(Btn)).SetParentComponent(Self);  end;  // Component serialized as Pascal - Endfinally  WebLabel1.EndUpdate;  WebEdit1.EndUpdate;  WebButton1.EndUpdate;  WebMemo1.EndUpdate;  WebComboBox1.EndUpdate;  WebPanel1.EndUpdate;  WebLabel2.EndUpdate;  WebImageControl1.EndUpdate;  Btn.EndUpdate;end;   I think the best solution is to integrate the DFM2PAS serialization in pas2js compiler. Each time the project is recompiled, all "form units" are automatically generated. and we can just add a directive at the LoadDFMValue for instance. //The source code below is displayed for informational purposes only 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 Unit1; {$mode objfpc}{$H+} interface uses  SysUtils, Classes, JS, Web,  WEBLib.Graphics, WEBLIB.Controls, WEBLib.StdCtrls, WEBLib.ExtCtrls,   WEBLib.Forms,  WEBLib.Dialogs; type  TForm1 = class(TWebForm)  private    { Private declarations }    WebLabel1      : TWebLabel;    WebEdit1         : TWebEdit;    WebButton1       : TWebButton;    WebMemo1         : TWebMemo;    WebComboBox1     : TWebComboBox;    WebPanel1        : TWebPanel;    WebLabel2        : TWebLabel;    WebImageControl1 : TWebImage;  public    { Public declarations }    procedure LoadDFMValues; override;    procedure WebButton1Click(Sender: TObject);    procedure WebComboBox1Change(Sender: TObject);  end; var  Form1: TForm1; implementation //{$R *.lfm} { TForm1 } procedure TForm1.LoadDFMValues;begin  inherited;  {$I 'Form1:impl'} end; procedure TForm1.WebButton1Click(Sender: TObject);begin  console.log('button clicked');  WebComboBox1.Items.Add(WebEdit1.Text);  WebComboBox1.ItemIndex := WebComboBox1.Items.Count - 1;  WebMemo1.Lines.Add(WebEdit1.Text);end; procedure TForm1.WebComboBox1Change(Sender: TObject);begin  WebLabel1.Caption := WebComboBox1.Items[WebComboBox1.GetItemIndex];end; initializationRegis terForm({$I %FILE%}, TForm1); end. ---------------------------------------------------------------------- RazorGrass · 2018-03-22 16:21 Hi warleyalex, I don't know if this related or even possible. I saw your post on Framework7 many months ago and am now ready to get going on a F7 project. I am seeing it was done with SmartPascal. Are the files downloadable, working, still a thing? Can it be ported to work in Lazarus? https://muut.com/i/framework7/getting-started:f7-with-delphi-pascal- like