> From: Nicolas Raitman
>
> Richard, thanks a lot I will try that, but suppose that I would like to
> write the entire structure, could I do the followig?
>
> DmWrite( JugadorPtr, 0, Jugador, size);
>
> or not? What should I do instead?

No, your structure contains two pointers:

  typedef struct
  {
  char * Nombre;
  char * NickName;
  } JugadorType;

and in your code, Jugador points to one string, not to the structure.  There
is no guarantee that the second string actually exists in memory immediately
following the first string.

If you want to save two strings in a single database record, you have two
options:

1. Create a struct that holds two arrays of Chars and save that in your
database:

  typedef struct
  {
  Char Nombre[22];
  Char NickName[10];
  } JugadorType;

This method makes it very easy to read and write the entire structure to the
database.  It has two big problems, however:  (a) you have to know the
maximum size of each string at compile time, and (b) every record uses the
same amount of space, even if the names you store are short.

2. Pack the two strings together into a single record and save that.  I.e.,
in the database you would store the two strings packed together like this:

Senor Delgato\0Cat\0

then when you read the database record, you have to unpack it to get back
two strings.

To see examples of how this is done, take a look at Neil Rhodes' book online
at http://www.palmos.com/dev/tech/docs/devguide/TableOfContents.htm or buy a
good book on Palm database programming.  There are several books listed at
palmos.com.


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