Solved

event for unnamed component

Posted on 2001-09-08
2
563 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

726 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