Sign in Join

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

Mailing lists / fpc-pascal / 2010-11

When do I need a component rather than a plain object?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Frank Church

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.

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

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

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?

PS. I asked this question in the Lazarus forum, but on reflection it is a FreePascal question and belongs here instead.

Frank Church ======================= http://devblog.brahmancreations.com
Michael Van Canneyt
to Frank Church
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.