I have done work with tables.  And I also don't like the passing pointers to
records that you unlock.  Most unstable.  Not recommended.

You are setting the item style to a labelTableItem.  Label table items do
NOT have custom draw routines.  The table's draw routine assumes that the
pointer is valid -- it doesn't check it, just uses it.  Bad, bad.

I would recommend you take one of three approaches.

#1.  Use custom table items with a custom draw procedure.  Give the record
number to the table with TblSetItemInt.  In your custom draw procedure,
access the record, lock its handle, draw the label, unlock the handle.  To
draw like the table does, set the text color to UIObjectForeground and font
to standard.  Get the width of your string with FntCharsWidth.  Add to your
x coordinate the column width and subtract the string width and subtract the
width of the colon character.  Use WinDrawChars to draw your string.
Increment your x coordinate by the string width.  Use WinDrawChar to draw
the colon character.  Just like table.c's DrawLabelItem :)
#2.  Allocate new memory for the labels (MemPtrNew), copy the strings in the
record to the newly allocated memory areas, give the table pointers to the
newly allocated memory.  Be sure to free this memory on form close.
#3.  Lock the records on form enter and keep them locked until form close --
this may, of course, be impossible and I certainly consider it dangerous.

-bob mckenzie, palmsource pdx

-----Original Message-----
From: Matt Hebley [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 7:27 AM
To: Palm Developer Forum
Subject: Re: Tables & Databases



> > Table Equivilant:
> > ===============================================================
> >
> >   for (i = 0; i < numRecs; i++) {
> >      recH = DmQueryRecord(gDB, i);
> >       if (recH) {
> >
> >    TblSetItemStyle (tblS, i, C_SITE, textTableItem);
> >    TblSetLoadDataProcedure(tblS, C_SITE, loadDataCallback);
> >    TblSetSaveDataProcedure(tblS, C_SITE, SaveDataCallback);
> >     recP = (ParkITDBPtr)MemHandleLock(recH);
> >
> >    TblSetItemStyle (tblS, i, C_CLNT, labelTableItem);
> >    TblSetItemPtr   (tblS, i, C_CLNT, recP->Client);
> >
> >    TblSetItemStyle (tblS, i, C_REGO, labelTableItem);
> >    TblSetItemPtr   (tblS, i, C_REGO, recP->Rego);
> >
> >       TblSetRowUsable (tblS, i, true);
> >       MemHandleUnlock (recH);
> >
> >      }
> >    }
> >
> >  TblDrawTable(tblS);

Yep, we're seeing it. Guess we were all waiting for someone else to answer
it.

I haven't done too much with tables, so take what I say with a pinch of
salt...

First thing. You assign pointers to columns C_CLNT, and C_REGO, but you 
then unlock the handle of the structure that contains the pointers. I'm 
guessing you know what you are doing here, and that the pointers remain 
valid despite the handle lock state. (I believe that the table doesn't 
actually use these pointers, however, your custom routines can.)

Second. Check that numRecs is what you want to use. Tables can have more 
rows than are displayed. I don't know if you used TblGetNumberOfRows.

Third. Figure out where and what the handle errors are. You may have 
everything set up OK, but are just not doing the right thing in your
callbacks.

Matt


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

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

Reply via email to