Solved

TCollection in the Object Inspector

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

20 Experts available now in Live!

Get 1:1 Help Now