Barry,

Char *StrCopy (Char *dst, const Char *src) is failing because you are tyring to write to the string literal text which you can't do. Notice the order or src and dst. It think you have it backwards.
Call MemHandleUnlock after you call StrCopy() but before you call FldSetTextHandle();
void FldSetTextHandle (FieldType *fldP, MemHandle textHandle) takes a MemHandle not a char * so pass it recH.


You can StrCopy() directly to the pointer you get back from FldGetTextHandle() but make sure it's long enough to hold the string.
You don't need to call FldInsert() if you are going to call FldSetTextHandle().


At least that's my take on what's wrong...

Dana

Barry Jaques wrote:

The following script crashes at StrCopy:
FieldPtr fld;
MemHandle recH;
MemHandle oldTextH;
Char *record;
Char *text;


   // Get a pointer to the memo field.
   fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, ViewErrandField));
   CurrentRecord = 0; // This is the CurrentRecord entry
   DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);

   recH = DmQueryRecord (MemoDB, CurrentRecord);

record = (Char *) MemHandleLock(recH);
MemHandleUnlock(recH);
text = "unfit";//just something to bite on!
StrCopy(text, record);
oldTextH = FldGetTextHandle(fld);
FldInsert(fld, text, StrLen(text));
FldSetTextHandle (fld, record);
//Dispose of the old handle to prevent a memory leak.
if (oldTextH)
MemHandleFree(oldTextH);
I have this script which compiles OK but when I run it on POSE it
crashes with the message 'DataMgr (1.0) just wrote to memory location
0x0004C722, which is in the storage heap' at StrCopy.


If I use FldSetTextHandle (fld, record); instead I get the message,
'illegal implicit conversion from char* to struct _opaque*'.
Sorry this is just trial and error but my C knowledge is very
limited and none of the Palm docs or books are game to talk about
the topic of getting data into fields.
I can get the data into the field OK but I am trying to prevent
editing the memopad data.
Barry






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

Reply via email to