Solved

event for unnamed component

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

13 Experts available now in Live!

Get 1:1 Help Now