> -----Original Message-----
> From: Dev Nair [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 08, 2001 11:45 PM
> To: [EMAIL PROTECTED]
> Subject: Need some help on Palm OS Tables
>
>
>
> Hi,
> Hello Richard, I'm Dev and am somewhat new 2 Palm OS
> programming. I've seen quite a few replies given by u, so
> guess that u can probably solve my problem. Sorry for
> directly writing 2 u at ur email-id. I'll describe what
> actually is the problem.
>
>
I would suggest that in the future you try posting to the Palm Dev Forum
You can find out more about it at www.palmos.com/dev/tech/support/forums/
but basically posting your question so dozens of other developers
can read it is more likely to get you the help you need than sending
the question privately to one or two. I have taken the liberty
of cc'ing this msg to the palm dev forum in hopes that the other
developers there will catch any misteaks I make on my discussion
here.
> I've got a problem with handling Palm OS tables. I've got a
> table with 3 rows and 4 columns. 3 columns are filled with
> static data and only one of the columns contain field data
> from a database record. I've kept one column as numeric type
> and rest all Label type. Now, I retrieve 3 records which are
> currently there in the database and in a loop try to display
> a particular field in one of the table's columns.
>
> I find that the the column containing database data always
> displays the last record's data in all the rows. All the
> other columns are displaying data as required. I'm printing
> them in an Alert also, where all the record data in the loop
> are changing as in the database, but finally in the table
> column only last record's field value is being dispalyed.
>
> I've tried many different ways to tackle this problem but
> with no success. Please let me know if you can help me out.
> Logically allz fine, but somehow something isn't working.
>
>
> So, do write back if you have any ideas or ways out of this problem.
>
Unfortunately I have not yet implemented any application using
tables. Most of what I've wanted done so far I could do with a
list. From what I've read, though, the technique is similar to
the one you use w/ an "owner draw" list. There is a call-back
function that you define that the operating system calls whenever
it needs to draw a cell in the table.
So ... on to the issue at hand ...
I'm assuming that the static data isn't causing you
any problems, so I'll just try to figure out the last column.
Remember that when you initialize the form you have to do
a _lot_ of work telling it about the table. You have to
set each column as "usable", and tell the operating system the
type of data in each column for each row ... so you probably
already have something that looks like this:
for (col=0; col<4; col++)
TblSetColumnUsable(tableP, col, true);
for (row=0; row<3; row++) {
for (col=0; col<3; col++)
TblSetItemStyle(tableP, row, col, labelTableItem);
TblSetItemStyle(tableP, row, 3, numericTableItem);
}
Plus you probably have some fixed code to fill in the labels
in the first 3 columns of each rode. (I won't even give any
guess at that code here).
Next comes trying to figure out what your problem might
be ...
You say:
> Now, I retrieve 3 records which are
> currently there in the database and in a loop try to display
> a particular field in one of the table's columns.
I assume then that you are using TblSetItemInt in order to
display this final column? Well ... actually that should
work ... perhaps there is some problem with pointers in
that loop, but without your actual code I can't check that ...
Instead of writing your own loop to load the table cells,
you might want to have the operating system do the looping
and just ask you for the data when it needs it. To do that
you must have written a function that looks something like this:
Err MyTableDataLoader (void *tableP, Int16 row, Int16 column, Boolean
editable, MemHandle *dataH, Int16 *dataOffset, Int16 *dataSize, FieldPtr
fld)
{
// do stuff here
}
and tell the operating system to use it for your fourth
colum by calling this when you initialize the form:
TblSetLoadDataProcedure (tableP, 3, MyTableDataLoader) ;
When the operating system is drawing a cell in the fourth column of your
table it needs to know what data to display, so it will call your
"MyTableLoader"
function with the row & column parameters and it will be up to that function
to look up the right record & return a pointer to the data. You need
to return the handle to your record as dataH, the offset in that record
to the beginning of the data for column3 as dataOffset and the size
of that as dataSize. Since you said it was integer data then the
dataSize would probably be sizeof(Int16). Remember that these are
pointers, so the code to set that would look like this:
*dataSize = sizeof(Int16);
I leave it to you to figure out how to set dataH and dataOffset,
as that would be dependant upon your record structure.
Note that all of this seems to be very confusing to some people. It may
be easier to set the item style to customTableItem and use
TblSetCustomDrawProcedure instead of TblSetLoadDataProcedure.
If you do this then your routine would be responsible not only finding
and loading the data, but drawing it as well ... but this seems easier
for more people to do correctly than passing back pointers to data offsets,
especially since it is quite similar to how the owner-drawn lists work.
You can find some information on using tables here, in the
on-line edition of the O'Reilly book:
http://www.palmos.com/dev/tech/docs/devguide/ch08.htm#P27_302
The online OS API reference for TblSetLoadDataProcedure
can be found here:
http://www.palmos.com/dev/tech/docs/palmos/Table.html#926936
Information about the callback function that you pass to
TblSetLoadDataProcedure (you have to implement this yourself)
can be found here:
http://www.palmos.com/dev/tech/docs/palmos/Table.html#927235
Hope this helps.
--
-Richard M. Hartman
[EMAIL PROTECTED]
186,000 mi./sec ... not just a good idea, it's the LAW!
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/