Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-10

streaming child components

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roland Schaefer

Hi,
I have another question regarding serialization. I need to stream child components, and here: http://wiki.freepascal.org/Streaming_components it says that "TComponent extends TPersistent by the ability to have child components". The rest I figured from reading the RTL sources, and I'm wondering if I'm using a suboptimal solution, since I don't really use anything built into TComponent besides overriding one method which is empty in TComponent.

What I'm doing is I have my TComponent descendants keep a TComponentList of children (which are not necessarily owned by the parent), and then I overwrite the GetChildren(Proc ...) method and have it call Proc for every child in the list. I also introduce a private FParent field which I set manually when a component becomes the child of another component.

Is that reinventing the wheel (probably with a flat tire), or should/can you do it this way?

Cheers, thanks a lot
Roland

Mattias Gaertner
to Roland Schaefer
Show quoted text 9 lines
Hi, I have another question regarding serialization. I need to stream child components, and here: http://wiki.freepascal.org/Streaming_components it says that "TComponent extends TPersistent by the ability to have child components". The rest I figured from reading the RTL sources, and I'm wondering if I'm using a suboptimal solution, since I don't really use anything built into TComponent besides overriding one method which is empty in TComponent.

Only one method? A little bit more is needed.

Show quoted text 9 lines
What I'm doing is I have my TComponent descendants keep a TComponentList of children (which are not necessarily owned by the parent), and then I overwrite the GetChildren(Proc ...) method and have it call Proc for every child in the list. I also introduce a private FParent field which I set manually when a component becomes the child of another component. Is that reinventing the wheel (probably with a flat tire), or should/can you do it this way?

The lazarus sources contain a complete example of how to write a TComponent descendant with Parent+Childs. The class TMyWidget can be found under examples/designnonlcl/mywidgetset.pas.

Mattias

Roland Schaefer
to Mattias Gaertner
The lazarus sources contain a complete example of how to write a TComponent descendant with Parent+Childs. The class TMyWidget can be found under examples/designnonlcl/mywidgetset.pas.

Thanks a lot! This cleared things up, and it seems I mostly got it right.

Best
Roland