At 05:45 PM 28/3/2002 -0800, you wrote:
>Just to make sure I'm on the right page - for the code snippet below, how
>would I make sure this is robust enough not to fail?
>(i.e. how would I want to write this so that it would fail gracefully if
>there isn't enough memory to allocate the handle?)
>
>Thanks,
>Ed.
>
>MemHandle h;
> UInt16 index = 0;
>
> DmSeekRecordInCategory(gClientsDB, &index, (UInt16) itemNum,
> dmSeekForward, dmAllCategories);
>
> h = DmQueryRecord(gClientsDB, index);
>
> if (h) {
> skelClientsDBType *p = (skelClientsDBType *) MemHandleLock(h);
> DrawCharsToFitWidth(p->Name, bounds);
> MemHandleUnlock(h);
> }
This is robust. There is no memory being allocated. MemHandleLock returns a
pointer to a database record that is already allocated, it is just that the
allocated memory will not move around while it is locked.
The question is what do you do if it doesn't find a record in the category....
Matt
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/