Solved

event for unnamed component

Posted on 2001-09-08
2
548 Views
Last Modified: 2011-09-20
Hi all.

I have a component which has property derived from TOwnedCollection.
Every item of collection is an object derived from TCollectionItem.
All items's property can be edited in designtime. All seems fine.

Now I have to add some event property to collection item. Nothing unusual.
I can see event name in object inspector, but can't assign it in designtime.

Error message:
"Can not create a default method name for unnamed component"

I added "Name" property to collection item and give names for all items, but it doesn't help.

Exploring VCL code I didn't found any object derived from TCollectionItem that has events.

I just want to be sure that it is not possible. Right? Can somebody guide me to the doc with explanations?

-----
Igor

PS:
I know that I can move property to main component level and use collection item as parameter to identify item which event occurs.
0
Comment
Question by:ITugay
2 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 300 total points
ID: 6467236
I tried this in Delphi 5 and it works correctly also in design time. The error message you mention does not occur here. Maybe I haven't understood the problem well?

Regards Jacco

unit ButtonWithCollection;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TColl = class(TOwnedCollection)
  end;

  TCollItem = class(TCollectionItem)
  private
    FEvent: TNotifyEvent;
  published
    property Event: TNotifyEvent read FEvent write FEvent;
  end;

  TButtonWithCollection = class(TButton)
  private
    FColl: TColl;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Coll: TColl read FColl write FColl;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('SoSsA', [TButtonWithCollection]);
end;

{ TButtonWithCollection }

constructor TButtonWithCollection.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FColl := TColl.Create(Self, TCollItem);
end;

destructor TButtonWithCollection.Destroy;
begin
  FColl.Free;
  inherited Destroy;
end;

end.
0
 
LVL 9

Author Comment

by:ITugay
ID: 6470185
Hi Jacco,

yes, you are right, it works. I found where is the problem in my code.

type
  TFieldDefinition = class(TCollectionItem)
  ...
  function GetNamePath: string; override;
end;
..........
function TFieldDefinition.GetNamePath: String;
begin
  Result := GetDisplayName;
end;

If I comment this method then all works as expected. But only name of item in object inspector's combobox become unusefull "CompName.PropName[nn]". OK, it's not a problem, I will do something with it.

You help me a lot. Thanx. Otherwise I still keep thinking that it's not possible. So points increased :-)


-----
Igor
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

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…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 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

23 Experts available now in Live!

Get 1:1 Help Now