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

Bo Berglund bo.berglund at gmail.com
Mon Nov 15 16:32:34 CET 2010


On Sun, 14 Nov 2010 15:25:26 +0000, Frank Church <vfclists at gmail.com>
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.
>
>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?

According to what I have read in the WIKI you only install components
into Lazarus if they are visual and you really need them to be part of
a visual form.
In all other cases you should not install a component in the IDE,
instead you instantiate the objects from that component in code.

I think that from this follows that you can base such a class on
TObject rather than TComponent for all "normal" uses.

TObject also has properties:

TMyObject = class(TObject)
  FMyProp: Cardinal;
private
  function  GetMyProp: Cardinal;
  procedure SetMyprop(Value: Cardinal);
protected
public
  property MyProp: Cardinal read GetMyProp write SetMyprop;
end;

A setter and a getter are connected to the property as a gobetween to
the field that holds the value itself..

-- 

Bo Berglund
Developer in Sweden





More information about the Lazarus mailing list