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

Max Vlasov max.vlasov at gmail.com
Wed Nov 17 15:07:40 CET 2010


2010/11/16 Frank Church <vfclists at gmail.com>

>
>
> Setting properties in code is fine, and some design IDE component can be
> used to generate the source code to initialize them at runtime.
>
>
Thought about it recently, I think that having some IDE menu item "Paste as
code" (for objects as text in clipboard) or external tool would be grea. And
even if IDE doesn't have it, it's ok, I'll be glad living with a tool :). I
see at least two ways to implement this

1. Converting the text to single call with incoming text accurately fitted
to 'bla-bla-bla''#1310+ lines. The format of this text is exactly the same
as text from lfm/dfm, just converted to be compatible pascal string constant

PROS:
- easy to implement, one even doesn't have to know anything about the text
format, just use the routines Lazarus uses itself.
- theoretically the same tool/wizard can also accept this fragment back in
order to temporal designer edit since the conversion is not so complex
CONS:
- rtti info have to be available at the time of creating so either
explicitly the code should contain RegisterClass call or the developer
should remember about this (correcting the statement after the first run).
- component references can not be automatically resolved
- if some property was changed/removed, only run-time error for corrections
would be possible

2. Other way is to convert it to correct pascal assignments/calls (the
latter for TStringList, TCollection etc)
PROS:
- compile-time errors for everything: absent uses entry, non-existing
property etc, not-resolved component reference assigment.
- easy and safe in-place editing also with a little help of the compiler.
CONS:
- much harder to implement, one must know everything about the text lfm/dfm
format for correct conversion.
-also much harder to implement backward conversion.

Did I forget something? Is it something also deserved to be mentioned?

Thanks,

Max Vlasov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20101117/0f57fca4/attachment-0003.html>


More information about the Lazarus mailing list