[fpc-pascal] streaming child components

Mattias Gaertner nc-gaertnma at netcologne.de
Sun Oct 25 22:07:21 CET 2009


On Sun, 25 Oct 2009 21:56:01 +0100
Roland Schaefer <roland.schaefer at fu-berlin.de> wrote:

> 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.


> 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



More information about the fpc-pascal mailing list