Event Handling

A PocketC native palm library offering native forms and assorted utilities

Postby Manoj on Mon Dec 08, 2003 6:49 pm

Hi Joe,

While designing I soon realised that an app would typically have a huge switch statement in the main event loop that would cater to _ALL_ the event-generating widgets of _ALL_ the forms.

ie, No.of 'case' statements = No.of forms * No.of event-generating widgets on each form.

I was wondering if it is possible to split the main event loop into smaller methods (functions) that each handles only one form.

I read up on EHAND Event handler and it seemed somewhat appropriate , but I do not know if and how I can put it to my use.

As an alternative, I intend to use a nested switch statement, the outer for identifying a form and the inner for identifying a button in that form.

Load FORM1 //ID=3000
Load FORM2 //ID=4000
Load FORM3 //ID=5000
Draw FORM1
while (e = Fevent(1)) {
int f = FCtl(FORMID, -1 /* unused */);
switch(f) {
case FORM1: form1EventHandler(e); break;
case FORM2: form2EventHandler(e); break;
case FORM3: form3EventHandler(e); break;
default: break;

void form1EventHandler(int e) {
switch(e) {
case BTN1_FORM1: //do something; break;
case BTN2_FORM1: //do something; break;
case BTN3_FORM1: //do something; break;
default: break;
void form2EventHandler(int e) {
switch(e) {
case BTN1_FORM2: //do something; break;
case BTN2_FORM2: //do something; break;
case BTN3_FORM2: //do something; break;
default: break;

What do you say? Is above usage correct or EHAND a better option?

Posts: 16
Joined: Mon Sep 15, 2003 2:08 pm
Location: United Kingdom

Postby jstadolnik on Mon Dec 08, 2003 8:42 pm

EHAND function are intended to capture special events that can be trapped by Fevent(), such as button repeate events, field changes, etc.. What you are doing is efficent... essentially having different switch/case constructs for each form.


The PToolboxLib guy.
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Return to Pocket Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest