From: "druid" <[EMAIL PROTECTED]>
> there has got to be a better way, this could get ugly
> with 10 fields or so
>
You could wrap the test and alert in a private work function
that's passed the name and index of the field. That means
that your main code would just be:
if (handleField("Name", fldName))
{
if (handleField("Number", fldNumber))
{
}
}
That's slightly less efficient, but is a lot easier to read. It also
stays simple even if the logic associated with each field becomes
more complex.
For this sort of problem I've also sometimes used a loop with
a case statement:
for (fieldnum = 0; fieldnum < FIELDCOUNT; ++fieldnum)
// common set up logic
switch (fieldnum)
{
case 0: // do stuff for field zero
break;
case 1: // do stuff for field one
break;
// etc...
}
// common error check and clean up logic
if (err != NOERROR)
{
break;
}
} // end field for
which isn't as clean as a worker function but is useful where
the worker function would otherwise need to pass a dozen
parameters in and out. It's essentially just using the loop to
step through a sequence (a simple state machine) to ensure
that the before and after logic in always consistent.
Chris Tutty
> #include <PalmOS.h>
> #include "testaleart.h"
> #include "testaleart_res.h"
> Char testdata[256], testdata1[256];
> Boolean nofield = false;
> UInt16 status;
>
> static Boolean frmMain_frmTestButton_OnSelect(EventPtr event)
> {
> UInt16 fld;
>
> // Insert code for frmTestButton
>
> GetFieldData( fldTest, testdata, 255 );
> if(nofield)
> {
> status = FrmCustomAlert(frmAleart, "Name", NULL, NULL);
> nofield = false;
> }
> else
> {
> GetFieldData( fldTest1, testdata1, 255 );
> }
> if(nofield)
> {
> status = FrmCustomAlert(frmAleart, "Number", NULL, NULL);
> nofield = false;
> }
> else
> {
> file://go to routine to save records
> }
>
>
>
> return true;
>
> }
>
>
>
>
>
> Boolean GetFieldData (UInt16 fld, Char *text, UInt16 maxLen)
> {
> FormPtr pForm = FrmGetActiveForm ();
> FieldPtr pField = FrmGetObjectPtr (pForm, FrmGetObjectIndex (pForm,
fld));
>
> if (text != NULL) *text = '\0'; // initialize
> if (text == NULL || pField == NULL)return false;
> if (FldGetTextLength (pField))
> {
> StrNCat (text, FldGetTextPtr (pField), maxLen);
> }
> else
> {
> nofield = true;
> }
> return true;
> }
>
> --
> For information on using the PalmSource Developer Forums, or to
unsubscribe, please see http://www.palmos.com/dev/support/forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/