Andre Augusto wrote:
I think I got the ideia!! By the way, is there a simple example that you know that follows the same ideia, for me to look at? Thanks a lot!
Andr� Augusto
Here are some code snippits from one of my apps. You can see that most forms have their own eventhandler, except for the error messages, which share the same handler.
Boolean ApplicationHandleEvent(EventPtr event)
{
Int16 formID;
FormType *frmP; if (event->eType == frmLoadEvent){
formID = event->data.frmLoad.formID;
frmP = FrmInitForm(formID);
FrmSetActiveForm(frmP);
switch (formID){
case mainform:
FrmSetEventHandler(frmP, MainFormHandler);
return true;
case powerForm:
FrmSetEventHandler(frmP, PowerFormHandler);
return true;
<snip>
case errMsgFormTreo600Sound:
case errMsgFormTreo650Sound:
FrmSetEventHandler(frmP, errMsgFormHandler);
return true;
<snip>
}
}
return false;
}...and here's that event handler. You can see that when the user presses the OK button, it will set a different pref value depending on which of the 2 forms was active at the time.
Boolean errMsgFormHandler(EventPtr eptr)
{
FormPtr form = FrmGetActiveForm();
Boolean handled=false;switch (eptr->eType){
case frmOpenEvent:
FrmDrawForm(form);
ClearEventQueue();
break;
<snip>
case ctlSelectEvent:
if (eptr->data.ctlEnter.controlID!=buttonID_OK){
if (FrmGetFormId(form)== errMsgFormTreo600Sound)
prefs.errorMsgTreo600Sound = !CtlGetValue(FrmGetObjectPtr(form, FrmGetObjectIndex(form, CheckboxID_noRepeat)));
if (FrmGetFormId(form)== errMsgFormTreo650Sound)
prefs.errorMsgTreo650Sound = !CtlGetValue(FrmGetObjectPtr(form, FrmGetObjectIndex(form, CheckboxID_noRepeat)));
}
else
FrmGotoForm(prefs.lastForm);
break;
<snip>
default:
}
return handled;
}
Bob.
Robert Moynihan wrote:
You can certainly use the same form handler for multiple forms, or multiple handlers for one form. You just have to tell the OS which handler you want to use at the momemt. If you use the same handler for multiple forms, you will likely want to do SOME things a little different on each form, so you might set a flag upon loading each form so that you know which one is current; something like "prefs.currentForm=form##" upon loading each form. Or you could test the form dynamically when you are in the handler using something like "if (FrmGetActiveForm()==FrmGetFormPtr(form##)) ...". Bob.
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
