?
Solved

TCollection in the Object Inspector

Posted on 2002-04-04
2
Medium Priority
?
506 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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

719 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