Eliah NInyo wrote in message <34442@palm-dev-forum>...
>
>hello,
>
>i have an application with a database.
>i have a form where i fill in data which i want to keep in the database
>record.
>
>i creat a database and a record, and this stuff is ok.
>
>the problem start here:
>
>i get a pointer to the text of every field i have,
>
>hFld1 = FldGetTextHandle ( ptrToTheField );
>// FieldPtr    ptrToTheField = (FieldPtr) FrmGetObjectPtr ( ptrToTheForm,
>resorce_id);
>
>CharPtr pFld1 = (CharPtr) MemHandleLock (hFld1);
>
>and so on to Fld2, Fld3 ...
>( not all the fiels r text fields, one is a Ctrl field and more )
>
>then i set the fields values to the record,
>
>Err err = DmWrite ( p, offset, TextP, StrLen ( TextP ) + 1 );
>// p is a poiter to the record,
>// offset is a number which i change according to the string length (it
>works good, i know it for the
>   debugging process),

Remember you said this ...

>// TextP is the poiter to the text of the field. actually it points to
>pFld1...N (N fields).
>
>the problem start when i wand to draw Fld1, Fld2 and Fld3 in a table row
>with the apropriate function. ( TableDrawFunc... )
>to get the data of a fiels i call a sample function that return CharPtr,
>
>the_Text = GetTheFieldText ();
>
>GetTheFieldText is define like this -
>
>CharPtr GetTheFieldText ( void )
>{
>    return (pForm -> Fld1 );
>}
>// pForm is a pointer to my record structure,

To your -record- structure, or the form?

>// Fld1 is one of the field of the structure.
>
>the function return the correct data for the first field. ( Fld1 is a
>numeric field which can get 8 digit only).
>for the secound fiels the data is not always right. if i enter to Fld1 all
>the 8 digits then i get the right data for Fld2, but if i enter to Fld1,
>lets say - 3 digits, i get only one or two chars from the Fld2 data. and
>fld3 is totaly incorrect. (even when i enter 8 digits to Fld1 )
>
>is anyone see an error?? is anyone has an idea how to see a record context
>??
>
>

I would have to see the struct you are using for pForm ... but if it
is indeed your record struct and not the form ptr, you still have
a problem.

Remember you said you change the DmWrite offset according to the
length of the strings you are storing?  Well ... that means you have
a variable-length record.  T'ain't no struct in the world that you can
map that onto.

You need to decode the stuff in your database properly in order
to use it.

One way is to have fixed width fields.


You can either write that directly (potentially wasteful), or keep writing
the way you are
now but use the struct w/ the fixed-width fields it as an intermediate
step when reading from the database.

You could also scan the db record to determine where the first
string ends (and thus where the second string begins) and remember
the start offsets of each string.

Check the O'Reilly book for the discussion of packing & unpacking
records.  It can be found online here:

http://palm.3com.com/devzone/docs/pptdg/ch06.htm#P615_35697

--
-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/

Reply via email to