BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Writing an event with parameters

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
Jet
Guest





PostPosted: Thu Aug 12, 2004 5:31 am    Post subject: Writing an event with parameters Reply with quote




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





PostPosted: Thu Aug 12, 2004 7:31 pm    Post subject: Re: Writing an event with parameters Reply with quote




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





PostPosted: Fri Aug 13, 2004 12:58 am    Post subject: Re: Writing an event with parameters Reply with quote




"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





PostPosted: Fri Aug 13, 2004 3:02 am    Post subject: Re: Writing an event with parameters Reply with quote


"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





PostPosted: Fri Aug 13, 2004 3:39 am    Post subject: Re: Writing an event with parameters Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.