[Lazarus] Inserting many components on form
Michael Van Canneyt
michael at freepascal.org
Mon Jun 27 23:17:54 CEST 2011
On Mon, 27 Jun 2011, fluisgirardi at gmail.com wrote:
>
>
> 2011/6/27 Mattias Gaertner <nc-gaertnma at netcologne.de>
> On Mon, 27 Jun 2011 16:31:56 -0300
> "fluisgirardi at gmail.com" <fluisgirardi at gmail.com> wrote:
>
> > 2011/6/27 Mattias Gaertner <nc-gaertnma at netcologne.de>
> >
> > >
> > > TComponent uses linear searches/notifications for each operation. So
> > > 1000 components is a bad idea.
> > > LCL adds even more searches/notifications, so 300 components is a bad
> > > idea.
> > >
> > >
> > And to make 4000 or 10000 components a good idea, what's must be changed?
>
> A lot.
> Are you sure you need that many components? For example some components
> uses TCollection and other classes to handle thousands of objects.
> Maybe if you explain what you want to achieve people can give an advice.
>
>
> Maybe I started my components with a wrong concept. Each component, represents a memory (or a set of memories) on a remote device (like a PLC) that can be
> read and/or written. These components can be linked with edits, labels, progress bars and others controls created to show/modifies/stores the value of these
> components.
>
> For now, I did only small projects using these components (using ~150 tags or components). Today, I started my first big project. On the first time, using
> the component wizard, I inserted 255*5+1 components. This action takes some time. After this, I tried using my wizard again, to insert 4000 components, and
> after this the IDE freezes.
>
> 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 (now, each below is a component)
> | |
> | |-> BlockItem (0..n items)
> | |-> BlockItem
> | | |
> | | |-> TagBit (0..n items)
> |
> |-> 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.
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.
Michael.
More information about the Lazarus
mailing list