 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jet Guest
|
Posted: Thu Aug 12, 2004 5:31 am Post subject: Writing an event with parameters |
|
|
hi, good day!
i'm writing a vcl component which is derived from TListView.
its columns has an editStyle like that of the
valuelist editor (similar to esSimple, esEllipsis,
and isPickList).
I want to create a published event which is similar to the
GetPickList event of the valuelisteditor. How am i going to
declare this event? Is the type TNotifyEvent?
From Borland C++ Builder Help :
"Notifications use the type TNotifyEvent, which carries only one
parameter, the sender of the event.
In some cases, it is not enough to know which event happened and
what component it happened to. For example, if the event is a
key-press event, it is likely that the handler will want to know
which key the user pressed. In these cases, you need handler
types that include parameters for additional information.
If your event was generated in response to a message, it is
likely that the parameters you pass to the event handler come
directly from the message parameters."
How will an event such as this be written and declared?
AssignPickItems(TObject *Sender, int ACol, TStrings *Values)
Thanks ... = )
|
|
| Back to top |
|
 |
Mark Guerrieri Guest
|
Posted: Thu Aug 12, 2004 7:31 pm Post subject: Re: Writing an event with parameters |
|
|
| Quote: | How will an event such as this be written and declared?
AssignPickItems(TObject *Sender, int ACol, TStrings *Values)
|
In your components header file, add:
typedef void __fastcall (__closure* TAssignPickItemsEvent)(System::TObject*
Sender, int ACol, Classes::TStrings* Values);
In the Private section of your class, add:
TAssignPickItemsEvent FOnAssignPickItems;
In the __published section of your class, add:
__property TAssignPickItemsEvent OnAssignPickItems =
{read=FOnAssignPickItems, write=FOnAssignPickItems);
In the class constructor, add:
FOnAssignPickItems = NULL;
Mark
|
|
| Back to top |
|
 |
Jet Guest
|
Posted: Fri Aug 13, 2004 12:58 am Post subject: Re: Writing an event with parameters |
|
|
"Mark Guerrieri" <mguerrieri (AT) cmsgrp (DOT) com> wrote:
| Quote: |
In your components header file, add:
typedef void __fastcall (__closure* TAssignPickItemsEvent)(System::TObject*
Sender, int ACol, Classes::TStrings* Values);
In the Private section of your class, add:
TAssignPickItemsEvent FOnAssignPickItems;
In the __published section of your class, add:
__property TAssignPickItemsEvent OnAssignPickItems =
{read=FOnAssignPickItems, write=FOnAssignPickItems);
In the class constructor, add:
FOnAssignPickItems = NULL;
|
Thanks, mark ... please check if i am about to do the right
thing : = )
Inside the control, I have a dynamic combobox, cbPick.
wherein
cbPick->OnEnter = CBPickEnter
TMyControl::CBPickEnter(TObject *Sender)
{
if(FOnAssignPickItems) {
TStringList *strList = new TStringList();
FOnAssignPickItems(this,FCol,strList);
for(int i=0; i<strList->Count)
cbPick->Items->Add(strList->Strings[i]);
delete strList;
}
}
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Aug 13, 2004 3:02 am Post subject: Re: Writing an event with parameters |
|
|
"Jet" <jettosan (AT) yahoo (DOT) com> wrote
| Quote: | TMyControl::CBPickEnter(TObject *Sender)
{
if(FOnAssignPickItems) {
TStringList *strList = new TStringList();
FOnAssignPickItems(this,FCol,strList);
for(int i=0; i<strList->Count)
cbPick->Items->Add(strList->Strings[i]);
delete strList;
}
}
|
You don't need the second TStringList, just pass the destination Items
directly:
TMyControl::CBPickEnter(TObject *Sender)
{
cbPick->Items->Clear();
if( FOnAssignPickItems )
FOnAssignPickItems(this, FCol, cbPick->Items);
}
Gambit
|
|
| Back to top |
|
 |
Jet Guest
|
Posted: Fri Aug 13, 2004 3:39 am Post subject: Re: Writing an event with parameters |
|
|
"Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote:
| Quote: | You don't need the second TStringList, just pass the destination Items
directly:
Thanks ... =) |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|