As a newbie I ran into many issues in this 2 months using Lazarus IDE. The LFM serialization mechanism which Lazarus ships with may be pretty useful and pretty straightforward for win/linux applications. In my current pet project, we're using the Lazarus IDE to generate an simple web app using the GUI approach.
Take a look at this mini video. I'm trying to mimic the Delphi TMS Web Core with the Lazarus IDE.
https://youtu.be/1Y6JoWUFEXw...desperately, I couldn't find a way to generate LFM-TO-PAS on-the-fly.
The idea is getting notified when a designer form is saved to generate respective pas code. Exactly, I have to serialize all .LFM forms from the current project to equivalent .pas code. I've been thinking this task can be performed "directly from the Lazarus IDE" (through a component or add on) we can stream forms as pascal code straightforward, I believe this will not add big overhead in output JS. However, I'm stuck on this plan, to create and initialize the components from a form directly from the IDE, we have to register and pass a form instance to some method, anyway.
For educational purpose, let's illustrate the issue. Suppose the current project has 5 forms:
program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, unit1, unit2, unit3, unit4, unit5
{ you can add units after this };
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.CreateForm(TForm3, Form3);
Application.Run;
end.
On the Lazarus IDE, we have a custom component on the toolbar. In somewhere in this component we have a code to access the current/active project, for instance:
var
LazProject: TLazProject;
begin
{ get the current project here }
LazProject:=LazarusIDE.ActiveProject;
...
From this LazProject reference variable we can have a list of all forms used in the active project, for instance. However, I can not easily access/instantiate forms (or any TComponent) directly from this point "LazarusIDE.ActiveProject"
Any idea how to instantiate a form by its name from the IDE?
TFormClass(GetClass('T'+aFormName)).Create(nil);
Any idea would greatly appreciated.
best regards,
warleyalex