> I defined the properties of a record in my database like this:
>
> #define DB_PEN_DOWN_START 0
> #define DB_PEN_DOWN_SIZE sizeof(WChar)
> #define DB_PEN_UP_START (DB_PEN_DOWN_START + DB_PEN_DOWN_SIZE)
> #define DB_PEN_UP_SIZE sizeof(WChar)
> #define DB_PENSTROKE_RECORD_SIZE (DB_PEN_DOWN_SIZE + DB_PEN_UP_SIZE)

I would suggest using a structure, particularly since it appears that it 
will always be the same size. So in your .h file (if other files will 
need this structure) or .c file (if not), do this:

typedef struct
{
     WChar     penDown;
     WChar     penUp;
} PenStroke;

and then to access it, do something like this:

VoidHand      hrecord;
PenStroke*    pStroke;

cursor = 0;
hrecord = DmQueryRecord( prevAppHackDB, cursor );
if( hrecord != NULL )
{
     pStroke = (PenStroke*)MemHandleLock( hrecord );
     if( pStroke != NULL )
     {
          char tempstr[10];
          StrIToH(tempstr, pStroke->penDown);
          StrToField(ControlPanelFormStartBtnField, StrLen(tempstr), 
tempstr);
          StrIToH(tempstr, pStroke->penUp);
          StrToField(ControlPanelFormEndBtnField, StrLen(tempstr), 
tempstr);
          MemHandleUnlock(hrecord);
          pStroke = NULL;
     }
}


Note a couple things:

The structure makes referring to penUp and penDown lots easier (easier to 
read, too).

I added sanity checks for the handle and pointer being non-null. This is 
generally a good idea to make things as bulletproof as possible.

I got rid of the WChar temp variable, it's not really needed (though it 
doesn't hurt anything if it's there, it just makes for more lines of 
code).

Use StrLen to get the size of a string: sizeof will always return the 
size of the whole array ( I think...), even if the string is empty or 
only a couple characters long. (Since StrToField is your own routine, I'm 
not sure that's what you want here, so ignore this if your routine wants 
the size of the whole array.)

I didn't try to compile this, so there may be a syntax problem, but you 
get the idea. Hope this helps.

Dave Johnnson

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to