Doh,
I hate not seeing the simple errors! I've corrected the errors as
far as I can see them, but the pack procedure still isn't working.
I've stepped through the code and found that one of my strings I'm
trying to pack is being reset to zero length during the pack
procedure, so even though the length of the record is being
calculated correctly at the start of the procedure, data is written
incorrectly. I've summarised the code below, any additional halp
would be great, as this is driving me nuts!
Cheers,
Nick
void PackDriver(DriverInfo *driver, MemHandle driverDBEntry)
{
UInt16 length = 0;
Char *s;
UInt16 offset = 0;
length = (UInt16) (StrLen(driver->idname) +
StrLen(driver->name) + StrLen(driver->team) +
StrLen(driver->carnum) + StrLen(driver->nation) + StrLen(driver-
>dob) +
StrLen(driver->champ) + StrLen(driver->debut) +
StrLen(driver->tpoints) + StrLen(driver->twins) +
StrLen(driver->tpodiums) + StrLen(driver->born) +
StrLen(driver->lives) + StrLen(driver->status) +
StrLen(driver->height) + StrLen(driver->weight) +
StrLen(driver->website) + 17);
// calcs correct length of record
if (MemHandleResize(driverDBEntry, length) == 0) {
s = (Char *) MemHandleLock(driverDBEntry);
offset = 0;
DmStrCopy(s, offset, driver->idname);
offset += (UInt16) StrLen(driver->idname) + 1;
//etc for other strings
offset += (UInt16) StrLen(driver->twins) + 1; //offset correct
here
DmStrCopy(s, offset, driver->tpodiums); //this line seems to
reset driver->born to a zero string??
offset += (UInt16) StrLen(driver->tpodiums) + 1;// offset ok
DmStrCopy(s, offset, driver->born); //zero string is written
offset += (UInt16) StrLen(driver->born) + 1; //offset now wrong!
//rest of record written at wrong offsets.
MemHandleUnlock(driverDBEntry);
}
}
--- In [EMAIL PROTECTED], "Kevin OKeefe" <[EMAIL PROTECTED]>
wrote:
> Also, you'll need some room for nulls at the end of each string
(especially if using DmStrCopy which also copies the null into the
destination).
>
> Keivn
>
> -----Original Message-----
> From: Mark Wilden [mailto:mark@m...]
> Sent: Monday, December 23, 2002 9:12 AM
> To: Palm Developer Forum
> Subject: Re: Problem packing string-only database record.
>
>
> From: "Nick Morton" <[EMAIL PROTECTED]>
>
> > offset += (UInt16) sizeof(circuit->idname);
>
> Think you want a StrLen in there instead of sizeof.
>
> --
> For information on using the Palm Developer Forums, or to
unsubscribe, please see http://www.palmos.com/dev/support/forums/
>
>
> ------------------------------------------
>
> The information in this transmittal and any attachments is
privileged and confidential and is intended only for the recipient(s)
listed above. You are hereby notified that any unauthorized
distribution or copying of this transmittal or its attachments is
prohibited. If you have received this transmittal in error, please
notify Invivodata immediately at (831) 438-9550.
>
> ------------------------------------------
>
>
> --
> 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/