Solved

TCollection in the Object Inspector

Posted on 2002-04-04
2
499 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now