[Pas2js] Integrate the DFM2PAS serialization in pas2js compiler.

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Mar 6 00:06:56 CET 2018


On Mon, 5 Mar 2018 16:46:46 -0600 (CST)
warleyalex via Pas2js <pas2js at lists.freepascal.org> wrote:

> LFM/DFM-serialization mechanism which Lazarus/Delphi ships with may be pretty
> useful. 
>[...]
>   with WebMemo1 do begin
>     Name:='WebMemo1';
>     Left:=64;
>     Height:=145;
>     Top:=89;
>     Width:=215;
>     ExecCustomCSP(Lines,[#7'Strings'#1#6#8'WebMemo1'#0#0]);

TMemo.Lines is written using DefineProperties, i.e. needs TReader and a
binary stream to read. The pas2js classes unit does not have a TStream.
So this needs a replacement.


>[...]
> I think the best solution is to integrate this pascalstream/DFM2PAS
> serialization in the pas2js compiler.

The above data comes from the designtime RTTI. The compiler does not
have that data. The pascalstreamer must be an IDE addon.

 
> Each time the project is recompiled, all form units are automatically
> generated.

Sounds unnecessary.


> We can just add a directive at the LoadDFMValue method for
> instance:
> 
> procedure TForm1.LoadDFMValues;
> begin
>   inherited;
>   {$I 'Form1:impl'}
> 
> end;
> 
> //The source code below is displayed for informational purposes only
> -------------------------------------------------------------------------------
> 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;
> 
> initialization
> RegisterForm({$I %FILE%}, TForm1);

Why the RegisterForm in the initialization?

Mattias


More information about the Pas2js mailing list