TCollectionItem event

Hi all,
I want to add a TNotifyEvent to a TCollectionItem component.
When I tried to add code to that event, a message appeared saying "Can't create a method for an unnamed component".
Can you help me with that please.

Your co-operation is highly appreciated.

Comments

  • : Hi all,
    : I want to add a TNotifyEvent to a TCollectionItem component.
    : When I tried to add code to that event, a message appeared saying "Can't create a method for an unnamed component".
    : Can you help me with that please.
    :
    : Your co-operation is highly appreciated.

    Showing the code would help a little.
  • : : Hi all,
    : : I want to add a TNotifyEvent to a TCollectionItem component.
    : : When I tried to add code to that event, a message appeared saying "Can't create a method for an unnamed component".
    : : Can you help me with that please.
    : :
    : : Your co-operation is highly appreciated.
    :
    : Showing the code would help a little.
    :
    The object inspector can only add events to descendants of TComponent, which excludes TCollectionItem (direct descendant of TPersistent).
    If you still want to have an event in the TCollectionItem, you need to link it at run-time in your code. The problem is that it will never be called by windows itself, since the TCollectionItem is not part of the message chain.
  • heres an example

    [code]
    type
    TPTable = class(TCollectionItem)
    private
    FTableName: string;
    FOnScroll: TPDataSetNotifyEvent;
    protected
    function GetDisplayName: string; override;
    published
    constructor Create(Collection: TCollection); override;
    destructor Destroy; override;
    property TableName: string read FTableName write FTableName;
    property OnScroll: TPDataSetNotifyEvent read FOnScroll write FOnScroll;
    end;

    type
    TPTables = class(TOwnedCollection)
    private
    function GetItem(Index: Integer): TPTable;
    public
    property Item[Index: Integer]: TPTable read GetItem; default;
    end;

    begin

    constructor TPTable.Create(Collection: TCollection);
    begin
    inherited;
    FTableName := '';
    end;

    destructor TPTable.Destroy;
    begin
    inherited;
    end;

    function TPTable.GetDisplayName: string;
    begin
    Result := Trim(FTableName);
    if Result = '' then Result := inherited GetDisplayName;
    end;

    function TPTables.GetItem(Index: Integer): TPTable;
    begin
    Result := TPTable(inherited GetItem(Index));
    end;

    [/code]

    hope it helps
  • : heres an example
    :
    : [code]
    : type
    : TPTable = class(TCollectionItem)
    : private
    : FTableName: string;
    : FOnScroll: TPDataSetNotifyEvent;
    : protected
    : function GetDisplayName: string; override;
    : published
    : constructor Create(Collection: TCollection); override;
    : destructor Destroy; override;
    : property TableName: string read FTableName write FTableName;
    : property OnScroll: TPDataSetNotifyEvent read FOnScroll write FOnScroll;
    : end;
    :
    : type
    : TPTables = class(TOwnedCollection)
    : private
    : function GetItem(Index: Integer): TPTable;
    : public
    : property Item[Index: Integer]: TPTable read GetItem; default;
    : end;
    :
    : begin
    :
    : constructor TPTable.Create(Collection: TCollection);
    : begin
    : inherited;
    : FTableName := '';
    : end;
    :
    : destructor TPTable.Destroy;
    : begin
    : inherited;
    : end;
    :
    : function TPTable.GetDisplayName: string;
    : begin
    : Result := Trim(FTableName);
    : if Result = '' then Result := inherited GetDisplayName;
    : end;
    :
    : function TPTables.GetItem(Index: Integer): TPTable;
    : begin
    : Result := TPTable(inherited GetItem(Index));
    : end;
    :
    : [/code]
    :
    : hope it helps
    :
    This code will only allow you to create events by typing them out and linking them at run-time. Since the TCollectionItem isn't inherited from the TComponent, you cannot use the object inspector to link the event, which was Mero tried to do.
  • : This code will only allow you to create events by typing them out and linking them at run-time. Since the TCollectionItem isn't inherited from the TComponent, you cannot use the object inspector to link the event, which was Mero tried to do.
    :

    have you tried it?
  • [b][red]This message was edited by injektilo at 2003-11-2 0:37:32[/red][/b][hr]
    : : This code will only allow you to create events by typing them out and linking them at run-time. Since the TCollectionItem isn't inherited from the TComponent, you cannot use the object inspector to link the event, which was Mero tried to do.
    : :

    have you tried it?

    oh maybe one more class is needed, but i thought it was logical

    [code]

    type
    MyComp = class(TComponent)
    FTables: TPTables

    ..
    ....
    [code]


  • : [b][red]This message was edited by injektilo at 2003-11-2 0:37:32[/red][/b][hr]
    : : : This code will only allow you to create events by typing them out and linking them at run-time. Since the TCollectionItem isn't inherited from the TComponent, you cannot use the object inspector to link the event, which was Mero tried to do.
    : : :
    :
    : have you tried it?
    :
    : oh maybe one more class is needed, but i thought it was logical
    :
    : [code]
    :
    : type
    : MyComp = class(TComponent)
    : FTables: TPTables
    :
    : ..
    : ....
    : [/code]
    :
    :
    I haven't tried it, but I know one cannot place only descendants of TComponent on the form, since those are all named objects. Any other object types need to be contained within a TComponent object to be placed on the form.
  • ok if you say so, it must be correct
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories