Solved

TCollection in the Object Inspector

Posted on 2002-04-04
2
505 Views
Last Modified: 2013-11-23
Hi,

I have a TOwnedCollection where I cannot get its property editor to popup
in the Object Inspector.
I know this is an owner problem, but I cannot figure it out.

The collection is attached to a TPersistent that is attatched to a
TComponent.
That is, the structure looks like this:
TComponent
    TPersistent
        TOwnedCollection

Now if I attatch the collection to the component, there's no problem. So
I thought I'd just pass the reference when creating the persitent so that
reference could be set as the owner of the collection. But it does not
work.

Is it at all possible to get a collection to popup when it's not attached
to the main component ?

Please advise,
Thanks

/Johnny
0
Comment
Question by:JustinCase
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 200 total points
ID: 6923083
I found out from the code of the TCollectionEditor that the TPersistent subclass needs an owner. This is done by overriding the GetOwner method of TPersistent. Then everything works (in D6 update 2 at least).

Here is a sample that has a OwnedCollection directly and via the TPersistent. Both show a collection editor in the IDE.

Regards Jacco

unit Unit1;

interface

uses
  Classes;

type
  TItem = class(TCollectionItem)
  private
    fBool: Boolean;
  published
    property Bool: Boolean read fBool write fBool;
  end;

  TPers = class(TPersistent)
  private
    fOwner: TPersistent;
    fColl: TOwnedCollection;
  protected
    function GetOwner: TPersistent; override;
  public
    constructor Create(aOwner: TComponent);
    destructor Destroy; override;
  published
    property Coll: TOwnedCollection read fColl write fColl;
  end;

  TTest = class(TComponent)
  private
    fPers: TPers;
    fColl: TOwnedCollection;
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Pers: TPers read fPers write fPers;
    property Coll: TOwnedCollection read fColl write fColl;
  end;

procedure Register;

implementation

{ TPers }

constructor TPers.Create(aOwner: TComponent);
begin
  inherited Create;
  fOwner := aOwner;
  fColl := TOwnedCollection.Create(Self, TItem);
end;

destructor TPers.Destroy;
begin
  fColl.Free;
  inherited Destroy;
end;

function TPers.GetOwner: TPersistent;
begin
  Result := fOwner;
end;

{ TTest }

constructor TTest.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fPers := TPers.Create(Self);
  fColl := TOwnedCollection.Create(Self, TItem);
end;

destructor TTest.Destroy;
begin
  fColl.Free;
  fPers.Free;
  inherited Destroy;
end;

procedure Register;
begin
  RegisterComponents('Jacco', [TTest]);
end;

end.
0
 

Author Comment

by:JustinCase
ID: 6923597
Great,

Thanks for the help.
/Johnny
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question