[Lazarus] When do I need a component rather than a plain object?

Sven Barth pascaldragon at googlemail.com
Sun Nov 14 16:31:21 CET 2010

On 14.11.2010 16:25, 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.

Do you mean setting properties during runtime or just using the concept 
of properties?

Properties themselves are already supported by TObject, for setting 
properties at runtime the RTTI must be enabled which is done by 
surrounding your class declaration with "{$M+}...{$M-}". Then 
"published" will be enabled to allow the streaming of properties. 
Alternatively you can derive from TPersistent which has RTTI already 

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

I believe that's introduced by TComponent, but it could also be further 
up... (ok... according to 
http://www.freepascal.org/docs-html/rtl/classes/tcomponent.html I'm 
right ^^ )

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

I'm sorry, but I don't understand what you mean here.

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

Basically they are the same, but it might be that Lazarus has an extra 
TLCLComponent inheriting from TComponent...


More information about the Lazarus mailing list