[Lazarus] Inserting many components on form
Martin
lazarus at mfriebe.de
Tue Jun 28 00:00:07 CEST 2011
On 27/06/2011 22:17, Michael Van Canneyt wrote:
>> I thought use the TCollection, but I don't know if I can represent
>> the following configuration (it's a example, it can have how many
>> PLCBlocks, BlockItems,
>> TagBit, PLCNumbers or PLCStrings the owner of project wants):
>>
>> Owner (TCollection)
>> |
>> |-> PLCBlock
>> | |
>> | |-> BlockItem (0..n items)
>> |
>> |-> PLCNumber (0..n items)
>> | |-> TagBit (0..n items)
>> |
>> |-> PLCString (0..n items)
>>
>> Some idea?
>
>
> In a collection that is written to stream, all items must be of the
> same type, because when reconstructing the collection, 'Add' is called.
>
> There are 2 ways out of this:
> - Merge PLCBlock, PLCNumber, PLCString to a single type
> - Create different collections, each with a unique type.
>
> If you absolutely need different types, you'll need different
> collections.
You can also define a special CollectionItem, that has a published
property for each of the possible types.
And then have an prop-editor that hides this away.
However, it does not fully solve the issue.
If your objects need to interact with other Components such as TEdit...
then you need to register a Notification anyway => so your object learns
if the Edit is destroyed (otherwise you may get a dangling pointer)
>
> Then, there is nothing to stop you from nesting collections. i.e.
> PLCBlock can have a collection BLockItems which contains items of
> class BlockItem. They will be streamed correctly.
>
> But the fastest (in terms of streaming and code speed) may be to have
> something like a TTreeNode object, and use DefineProperties to stream
> it. That's of course more coding for you.
You can also look at what TSynEdit does for the gutter (Gutterparts).
They are still components, but IIRC the ownership is no longer with the
form => that ultimately should reduce the size of some of the big lists
(e.g notification list, child list, ....)
That is normally all components are owned by the form, so they are all
in the component-list of the form, but if they are owned by an other
component (or several).....
But you need to get to know some of the details of streaming...
More information about the Lazarus
mailing list