[fpc-pascal] When do I need a component rather than a plain object?

Michael Van Canneyt michael at freepascal.org
Sun Nov 14 19:19:52 CET 2010



On Sun, 14 Nov 2010, Frank Church wrote:

> Does TObject have all the capabilities of TComponent apart from things like streaming and being used from the IDE component palette?
> 
> I want to create an object which has all the capabilities like getting and setting properties, and I want to know whether I need to
> inherit from TObject or from something further down the hierarchy.

If you need published properties (RTTI) then you can descend from TPersistent.

Or, you create a class that descends from TObject, for instance TRTTIObject
and compile it under {$M+}, and derive all your objects from that.

> 
> Another aspect is ownership. Does ownership require objects to be derived from TComponent?

Yes. Unless you care to re-implement the TComponent behaviour.

> 
> Is a TPersistent adequate if manipulating the object from the IDE isn't needed?

Yes.

> Last but not the least, is the FreePascal TObject/TComponent system more or less the same as Delphi's, or are there some major
> differences?

It is the same. At least we try very hard to keep it so :-)

Michael.



More information about the fpc-pascal mailing list