> From: Prashanth
>
> no that wasn't the problem, even if i gave
> an array of one[20]and gave the offsetof macro it was
> reading from the end of the first four bytes.!!! however
> i did it withot using the offset macro.had to calculate
> the offset and do it...i have found a solution but i
> still don't know as to what caused the error for this.
>
The SDK contains the OffsetOf() macro in PalmTypes.h, which normally gets
included in each project. As far as I know, that macro correctly returns
the offset of any structure member. How did you calculate the offset
without the macro? Counting bytes may not be accurate all the time due to
structure padding (to word align each member).
Also, I went back and read your original post, which included this:
FldSetText
l_fldP,l_fieldH,(UInt32)OffsetOf(myrecordtype,text),sizeof(g_record->text)+1
) ;
Maybe you should post the myrecordtype structure definition, plus the code
that sets l_fldP and l_fieldH. The above line is not correct. FldSetText
is defined like this:
void FldSetText (FieldType* fldP, MemHandle textHandle,
UInt16 offset, UInt16 size)
Note that the offset is a UInt16, not a UInt32.
Here's some sample code that uses FldSetText and the OffsetOf macro to set
some text from a DB record into a field:
typedef struct {
UInt16 aMember;
UInt32 bMember;
Char textMember[1]; // null terminated, will be longer
} MyRecordType;
...
MemHandle recordHandle;
MemHandle oldTxtHandle = FldGetTextHandle(field);
UInt16 txtLength;
UInt16 txtOffset = OffsetOf(MyRecordType, textMember);
if (oldTxtHandle)
MemHandleFree(oldTxtHandle);
recordHandle = DmGetRecord(theDB, theRecordNumber);
txtLength = (UInt16) MemHandleSize(recordHandle) - txtOffset;
FldSetText(field, recordHandle, txtOffset, txtLength);
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/