[Lazarus] When do I need a component rather than a plain object?

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Nov 16 13:19:28 CET 2010


On Tue, 16 Nov 2010 12:13:10 +0200
Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:

> Op 2010-11-16 11:45, Frank Church het geskryf:
> > It will be good if Lazarus can generate the source code to initialize
> > components at the start of a program, rather than stream them in,
> > hopefully in a future version. It makes revision control much easier, a
> > lot more transparent.

lfm files are simple text files just like pascal sources, so a
revision control system works the same.

There is a writer to write forms as pascal source (see
examples/pascalstream). But some properties can not be streamed, as
there is no simple source equivalent. For example images and icons.
They must be handled differently.
There are some other minor issues too.

The other big part is the reading the source code back to a form at
design time. That part is missing completely.

 
> Interestingly, this is exactly why I took the "generate source code instead
> of a form file" approach with fpGUI's UI Designer. One unit to worry about,
> predictable creation order, easy search-and-replace of components or
> properties (refactoring or global changes etc), components can be in the
> private section of forms where they belong, form upgrades to new or changed
> properties are easy to handle, easier form loading with high tolerance for
> error handling etc, etc...
> 
> I think Lazarus would benefit much from such an addition to it's form
> designer. 

I lack some imagination what the benefits are, except for smart linking.
Apparently some people have started such approach for Lazarus, but never
got feedback or help to continue, so I guess the work outweighs the
benefits.


> Pascal was supposed to be an easy language. 

So is lfm. At least I never heard complains that the lfm format is
hard to read.


> So why emulate the C-style (multiple files requirement) in Pascal?

Readability.
The form data easily grows to thousands of lines (e.g. icons).
Putting that into the source code breaks the readability rule to keep
every file small. And it is normally completely auto created and
edited by the IDE, so you very seldom edit it in code.

lfm files are loaded as resources. This can save some memory.

 
> Other toolkits that also generate source code from their Visual Form
> Designers are Visual Studio with .NET, Qt Designer, KDE Designer, etc.

Anyone is welcome to start a wiki page and/or extend the pascal form
reader/writer. When it works it can be added to the IDE as a third
type of resource.


Mattias




More information about the Lazarus mailing list