[Lazarus] How to load the Form from LFM-file at run time?

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Feb 18 18:37:48 CET 2013


On Mon, 18 Feb 2013 22:49:55 +1100
Александр С. <sss0991 at gmail.com> wrote:

> Example: there is a empty form that has an event: another form (from
> LFM-file) to be loaded instead of this form by double-clicking on old
> form at run time.
> 
> I tried several ways to do this, for example:
> 1.	File -> FileStream -> BinStream -> BinStream.ReadComponent(Form)
> 2.	ReadComponentResFile()

Have you seen the example in lazarus/examples/componentsstreaming/ ?

 
> These methods have drawbacks:
> a.	Double-clicking event from the old form doesn't disappear in new

When you load a lfm you have to start with a newly created form. There
is no method to "reset" a form to its initial state.


> b.	Need to register (RegisterClasses) for all the classes that are in
> the new form. Parsing the LFM-file, you can get the names of classes
> in the strings. What content should have a function "function
> StringToClass(AStr: string): TClass", to be able to call
> "RegisterClass(StringToClass(AStr))" ?

See the example.

 
> 3.	File -> StringStream -> Reader -> Reader.ReadComponent -> InsertComponent
> But my methods does not work. Could you please help me: how to load
> Form from LFM-file at run time?


Mattias




More information about the Lazarus mailing list