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
Solved

event for unnamed component

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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