[Lazarus] Published properties of classtypes

Inoussa OUEDRAOGO inoussa12 at gmail.com
Mon Mar 3 19:43:57 CET 2008


2008/3/3, Michael Van Canneyt <michael at freepascal.org>:
>
>
>  On Mon, 3 Mar 2008, Inoussa OUEDRAOGO wrote:
>
>  > 2008/3/3, Michael Van Canneyt <michael at freepascal.org>:
>  > >
>  > >
>  > >  On Mon, 3 Mar 2008, Ales Katona wrote:
>  > >
>  > >  > If you make a "class of something" published, it will compile, but the
>  > >  > property won't show in the OI. I'm not sure if it's supposed to work so
>  > >  > I'm asking here.. Vincent also mentioned "TTypeKind support tkClass" :)
>  > >  >
>  > >  > So.. should it be possible to use "class of " as published properties in
>  > >  > the OI?
>  > >
>  > >
>  > > No, because you cannot enter a value anyway.
>  > >  How will you resolve a text to a class pointer ?
>  >
>  > If the class is registered ( using RegisterClass() ), it can be found
>  > with FindClass().
>  >
>  > <code unit="classes">
>  >   procedure RegisterClass(AClass: TPersistentClass);
>  >   function FindClass(const AClassName: string): TPersistentClass;
>  > </code>
>
>
> You will find that this is almost never used. None of the classes in the
>  FCL/LCL is registered. They need not be registered, only exceptional cases
>  must be registered using this callback. That rather limits the use IMHO ?

It can be used to "virtualize" a class behavior as in the code below:
The worker object
receive some work items and based on his property HandlerClass, it
creates a handler instance
that process the items. Their could be some registered hanlder classes
for specific needs.
And it will be nice to be able to configure the worker component at
design through the OI(
  the editor could be a combobox with its items filed by the
registered class that inherits
  from TItemHandler ).

<code>
TItemHandler = class(TPersistent)
public
  procedure ProcessData(const AData); virtual; abstract;
end;
TItemHandlerClass = class of TItemHandler;

TWorker = class(TComponent)
private
...
  FHandlerClass : TItemHandlerClass;
  FHandler : TItemHandler;
...
published
  property HandlerClass : TItemHandlerClass read FHandlerClass write
SetHandlerClass;
end;

TAsyncHandler = class(TItemHandler)
public
  procedure ProcessData(const AData); virtual; override;
end;

TSynchroneHandler = class(TItemHandler)
public
  procedure ProcessData(const AData); virtual; override;
end;
</code>

-- 
Inoussa O.



More information about the Lazarus mailing list