Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

event for unnamed component

Posted on 2001-09-08
2
Medium Priority
?
601 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 1200 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

876 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