Andre,
This line...
StrCopy( FieldText, RecordPtr[*Offset]);
Should read
StrCopy( FieldText, RecordPtr+(*Offset));
The problem you have there is because using [] means an index into an array...
for example
char test[10];
test[3] = 'A';
this code makes the fourth character (indexes start at zero) a capital A
if you had
char *test[10];
your declaring 10 pointers to strings, not 10 characters in a string.
back to your code:-
StrCopy( FieldText, RecordPtr[*Offset]);<=================
this says copy from the RecordPtr array to the FieldText
and what you want is cpy fromthe record pointer PLUS an offset to the FieldText....
clear as mud :-)
You really need to read a book on C,or one of the many good tutorials available online.
Chris.
Andre Augusto wrote:
Thanks for your help! One more thing... can you tell me if this function is correct?
void SetFieldValue( FieldPtr field, UInt16 fieldLen, UInt16 *Offset) ///Problema em ler o valor Offset { MemHandle FieldTextHandle; const char* FieldText; DBRecordPtr RecordPtr;
FieldTextHandle = FldGetTextHandle(field); // Clear any existing text first FldSetTextHandle(field, NULL);
if (FieldTextHandle == NULL) { FieldTextHandle = MemHandleNew(fieldLen); } else { MemHandleResize(FieldTextHandle, fieldLen); }
FieldText = (const char*) MemHandleLock(FieldTextHandle); RecordPtr = (DBRecordPtr) MemHandleLock(CurrRecHandle);
StrCopy( FieldText, RecordPtr[*Offset]);<================= // *Offset += StrLen(RecordPtr[*Offset]) + 1;
MemHandleUnlock(CurrRecHandle); MemHandleUnlock(FieldTextHandle); FldSetTextHandle(field, FieldTextHandle); }
In PASCAL it's like this: procedure SetFieldValue(Field : FieldPtr;FieldLen : UInt16;var Offset : UInt16); var FieldTextHandle : MemHandle; FieldText : PChar; RecordPtr : PChar; begin FieldTextHandle := FldGetTextHandle(Field); // Clear any existing text first FldSetTextHandle(Field,nil);
if FieldTextHandle = nil then begin FieldTextHandle := MemHandleNew(FieldLen); end else begin MemHandleResize(FieldTextHandle,FieldLen); end;
FieldText := MemHandleLock(FieldTextHandle); RecordPtr := MemHandleLock(CurrRecHandle);
StrCopy(FieldText,@RecordPtr[Offset]); Offset := Offset + StrLen(@RecordPtr[Offset]) + 1;
MemHandleUnlock(CurrRecHandle); MemHandleUnlock(FieldTextHandle);
FldSetTextHandle(Field,FieldTextHandle); end;
The OffSet value that is passed to the function is "var OffSet". So how
can i pass it in C language? like &offset? Or *offset?
In the line that I put an arrow I have an error saying:
"function call 'StrCopy({lval} const char *, {lval} DBRecord *)' does not match 'StrCopy(char *, const char*)' "
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
