Solved

TCollection in the Object Inspector

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

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

Suggested Solutions

Title # Comments Views Activity
URL for downloading Google Chrome for Win XP 2 236
CheckListBox usage 3 83
Installshield for Embarcadero EX 10.1 Berlin 4 75
DBCtrlGrid, Delphi, Scroll 7 33
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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 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