I am working with codewarrior writing a program that stores this 
information:

typedef struct
        {
                short dia;
                short mes;
                short anio;
        } Fecha;

typedef struct
        {
                short id;
                Fecha captacion;
                char asignado[80];
                char contrato[80];
                char empresa[80];
                char legal[80];
                char contactar[80];
                char puesto[80];
                short estudios;
                char rfc[80];
        } Cliente;

with this method:

static Boolean CreateClientDB(void)
{
        Err err = false;
        Cliente *clientePtr = NULL;
        UInt16  count   = 0;
        MemHandle       record;
        Char    *pChar  = 0;
        UInt16 length = 0;
        UInt16 offset = 0;

        if (StrCompare(clienteActual.rfc, "")==0)
        {
                FrmCustomAlert(OkAlert, "no guardado, debe ingresar el
RFC", NULL, NULL);
                err = 1;
                return err;
        }

        clientePtr = &clienteActual;

        if (dbP==NULL)
                dbP = DmOpenDatabaseByTypeCreator('DATA', 'STRT',
dmModeReadWrite);
        else
        {
                DmCloseDatabase(dbP);
                dbP = DmOpenDatabaseByTypeCreator('DATA', 'STRT',
dmModeReadWrite);
        }
        err = DmGetLastErr();

        // create a new record at the end of a database (that gives
        // us a handle) and turn it into a pointer.

        count   = DmNumRecords (dbP);
        if (positionActual==0)
                record  = DmNewRecord (dbP, &count, sizeof(Cliente));
        else
                record  = DmGetRecord (dbP, positionActual-1);
        err = DmGetLastErr();
        pChar   = (Char *) MemHandleLock (record);

        // Write to the database with DmWrite (since writing through
        // the pointer won't work).
        err = DmWriteCheck(pChar, 0, sizeof(Cliente));
        err = DmWrite (pChar, 0, &clienteActual, sizeof(Cliente));

        // Then, unlock the handle and release the record.

        MemHandleUnlock (record);
        if (positionActual==0)
                positionActual=count+1;
        DmReleaseRecord (dbP, positionActual-1, true);
        SortDB();
        FrmCustomAlert(OkAlert, "salvado", NULL, NULL);
        return err;
}

It used to work, i even used a conduit but there was a problem with a
real 
handheld so I changed all of my MemPtrNew calls to MemHandleNew and 
MemHandleLock and then it started to store garbage in my db althought
the 
application seems to read it fine I check it outside the app (with the 
conduit and a pdb reader) and it seems that I only have garbage.

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

Reply via email to