You are mistaken. ApptDBRecordType has no member from
ApptTimeType type. It has a pointer to such structure,
which is absolutely different thing. ApptDBRecordType
object does not contain memory where ApptTimeType
object stored, so
DmWrite(d, offset, &when, sizeof ApptTimeType));
where d is ApptDBRecordType object overwrites the
pointer member with wrong value. You succeed to write
all ApptDBRecordType structure without error only
because sizeof(ApptTimeType) is 2 baits and
sizeof(ApptTimeType*) is 2 or 4(depending on code
model).
When reading the pointer *when* has wrong value and
you have memory access error.
As you see the ApptTimeType object has smaller or same
size as ApptTimeType*. Therefore it's better to
rewrite ApptDBRecordType :
typedef struct{
ApptTimeType when;
Int16 dayOfWeek;
Char *moduleName;
Char *classRoom;
Char *blockNo;
Char *levelNo;
}ApptDBRecordType;
Otherwise the only thing you can do is to store in the
record not only ApptDBRecordType structure but
ApptTimeType one too.
--- Low Pui Kuen <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a structure which one of its members is a
> structure.
> I use the DmWrite to write the structure and the
> rest to the storage memory.
> But when I unpacked the structure, I have memory
> access error.
> What wrong have I done? Thank you in advance.
>
>
/****************************************************************/
> typedef struct{
>
> TimeType startTime;
> TimeType endTime;
>
> }ApptTimeType;
>
>
> typedef struct{
>
> ApptTimeType *when;
>
> Int16 dayOfWeek;
> Char *moduleName;
> Char *classRoom;
> Char *blockNo;
> Char *levelNo;
>
> }ApptDBRecordType;
>
> typedef ApptDBRecordType * ApptDBRecordPtr;
>
>
> static void ApptPacked(ApptDBRecordPtr s,
> ApptDBRecordPtr d)
> {
> ApptTimeType when;
>
> Int32 offset = 0;
>
> when = *(s->when);
>
> DmWrite(d, offset, &when, sizeof(ApptTimeType));
> offset += sizeof (ApptTimeType);
>
>
>
>
>
>
> static void ApptUnpacked(ApptDBRecordPtr src,
> ApptDBRecordPtr dest)
> {
> Char str[20];
> ApptDBRecordType ApptRead;
>
> ApptRead = *src;
>
> dest->when = ApptRead.when;
> dest->dayOfWeek = ApptRead.dayOfWeek;
>
>
> TimeToAscii(when.startTime.hours,
>
> when.startTime.minutes,
> false,str);
> PrintString(str);
>
>
> Low Pui Kuen
>
>
_________________________________________________________________
> Send and receive Hotmail on your mobile device:
> http://mobile.msn.com
>
>
> --
> For information on using the Palm Developer Forums,
> or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/