Re: Adding "Items" property to component
From: Bob Richardson (bobr)
Date: 12/31/04
- Next message: Martin Harvey (Demon account): "Re: How to create a safe Key Generator?"
- Previous message: Rob Kennedy: "Re: How can I have a DLL write data to my application's form? (eg. DLLs and procedural type question)"
- In reply to: Rob Kennedy: "Re: Adding "Items" property to component"
- Next in thread: Bob Richardson: "Re: Adding "Items" property to component"
- Reply: Bob Richardson: "Re: Adding "Items" property to component"
- Reply: Rob Kennedy: "Re: Adding "Items" property to component"
- Reply: J French: "Re: Adding "Items" property to component"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 30 Dec 2004 16:23:26 -0800
After making these changes, I installed the component - then dropped in on a
form. When I tried to add some values to "Items" in the Object Inspector, I
got "Abstract Error" Have an idea what might be wrong?
"Rob Kennedy" <me3@privacy.net> wrote in message
news:33hffjF40g8keU1@individual.net...
> Bob Richardson wrote:
>> I've created a descendent of TCustomPanel and I'd like to add a property
>> "Items" just like the Items property of TListBox and some of the other
>> VCL components. Can someone point me in the right direction. Thank you.
>
> TListBox.Items is a TStrings object. All you need to do is declare a
> TStrings property in your component and attach it to property accessor
> functions. You'll also need a TStrings field in your class.
>
> type
> TStringHolder = class(TComponent)
> private
> FItems: TStrings;
> procedure SetItems(const Value: TStrings);
> public
> constructor Create(AOwner: TComponent); override;
> destructor Destroy; override;
> published
> property Items: TStrings read FItems write SetItems;
> end;
>
> constructor TStringHolder.Create(AOwner: TComponent);
> begin
> inherited;
> FItems := TStringList.Create;
> end;
>
> destructor TStringHolder.Destroy;
> begin
> FItems.Free;
> inherited;
> end;
>
> procedure TStringHolder.SetItems(const Value: TStrings);
> begin
> FItems.Assign(Value);
> end;
>
> The above should be all you need to have a simple component that you could
> put on a form and hold an arbitrary list of strings. (Storing the strings
> in a linked-in resource file would be better, if that's all you need.)
> Since FItems is actually a reference to a TStringList object, you can
> assign event handlers to its OnChange and OnChangin properties, and then
> your component will be notified whenever someone changes the contents of
> the list.
>
> --
> Rob
- Next message: Martin Harvey (Demon account): "Re: How to create a safe Key Generator?"
- Previous message: Rob Kennedy: "Re: How can I have a DLL write data to my application's form? (eg. DLLs and procedural type question)"
- In reply to: Rob Kennedy: "Re: Adding "Items" property to component"
- Next in thread: Bob Richardson: "Re: Adding "Items" property to component"
- Reply: Bob Richardson: "Re: Adding "Items" property to component"
- Reply: Rob Kennedy: "Re: Adding "Items" property to component"
- Reply: J French: "Re: Adding "Items" property to component"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|