Instantiate Form from IDE lazarus / 31-LCL ---------------------------------------------------------------------- warleyalex · 2018-04-12 22:58 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: 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 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: 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 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? 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 TFormClass(GetClass('T'+aFormName)).Create(nil);   Any idea would greatly appreciated. best regards, warleyalex ---------------------------------------------------------------------- warleyalex · 2018-04-25 21:42 Since we can access the active project from the Lazarus IDE, it should be easy to access its form units. Exactly, we just have to load the file interface, we can check if the unit has resource (e.g. form) and open and load the designer to access the project forms, as instantiated TComponents. 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 aDesigner:= TComponentEditorDesigner(LazarusIDE.GetDesignerWithProjectFile(AFile,t rue));if aDesigner=nil then   exit;  aDesigner.Form;