Re: Adding "Items" property to component

From: Bob Richardson (bobr)
Date: 12/31/04


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



Relevant Pages

  • Re: Garbage collection - performance test
    ... They are general string operations (splitting strings) not collections of ... and as such they don't affect the functionality of derived ... If you ever tried to derive your own classes from TStrings, as I did, ...
    (borland.public.delphi.non-technical)
  • Re: Comparing items is a list
    ... but TListBox.Items is only defined as TStrings ... single sort, however, unlike TStringList which has a CustomSort method. ... I have a grid where I tally how many duplicate strings were ... I have six sort routines based on numerical first, ascending or descending, ...
    (borland.public.delphi.non-technical)
  • Re: Can you dynamically resize an array?
    ... to omit it. ... the i'th item in the list of strings, ... some special syntax. ... TStrings indicates what you want ...
    (comp.lang.pascal.delphi.misc)
  • Re: Adding "Items" property to component
    ... TListBox.Items is a TStrings object. ... could put on a form and hold an arbitrary list of strings. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Copy TStringList to TListBox
    ... I have a TStringList containing some strings, ... but it seems that this only assigns pointers to the original ... The object array can only hold pointers or integer's etc, so when you did that, it simply copied the pointers which is what it does.. ... You can associate them with any object list in the Tstrings classes. ...
    (comp.lang.pascal.delphi.misc)