Thanks Robert!

I've followed your suggestions and so far my application appears to be
working fine. I was under the impression that once I unlocked my handle, I
couldn't "reuse" it for another string unless I freed it first. And if I
free it, I thought for sure the field would be empty. Right now I am able to
reuse the handle for my three fields, each time setting the handle to a
different database field (my database fields are NOT null terminated strings
by the way, but one large string with offsets at the beginning of the record
to let me know what size each field is). I haven't tried yet to see if I can
successfully edit/save the fields, and I'm sure I'll have some issues with
fldEnterEvent but thanks much for your help!

george r.

"Robert McKenzie" <[EMAIL PROTECTED]> wrote in message
news:56875@palm-dev-forum...
>
> Just a shot in the dark here, but perhaps you didn't
> understand the full import of Scott's suggestion.
>
> In effect, he seems to be recommending that you,
> at some point in your form's initialization, allocate
> separately, for EACH field you will display, a new
> chunk of memory, copy into it data from your record
> (or from wherever, 'tis up to you), then hand each
> form its own separate handle.
>
> Then, clearly, at some time in your form's finalization
> code, you would need to go through all of your fields,
> recover their data, paste it all back together, and
> store it safely away.
>
> As an example, suppose you have a database, each
> record of which contains three, concatenated, null-
> terminated strings which you will display in three
> fields of your form:  (this code off the top of my
> head; it may contain typos, etc; MyRecordIndex and
> MyFieldId are globals).
>
> void MyFormInit(FormPtr frm, DmOpenRef dbP)
> {
> UInt16 index;
> FieldPtr fld;
> MemHandle hRec, hFld;
> Char* pRec, pFld;
> int i;
> Int16 len;
> hRec = DmQueryRecord(dbP, MyRecordIndex);
> pRec = MemHandleLock(hRec);
> for (i=0; i<3; i++)
> {
> index = FrmGetObjectIndex(frm, MyFieldId[i]);
> fld = FrmGetObjectPtr(frm, index);
> len = StrLen(pRec) + 1;
> hFld = MemHandleNew(len);
> pFld = MemHandleLock(hFld);
> StrCopy(pFld, pRec);
> MemHandleUnlock(hFld);
> FldSetTextHandle(fld, hFld);
> pRec += len;
> }
> MemHandleUnlock(hRec);
> }
>
> void MyFormExit(FormPtr frm, DmOpenRef dbP)
> {
> UInt16 index;
> FieldPtr fld;
> MemHandle hRec, hFld;
> Char* pRec, pFld;
> int i;
> Int16 len = 0;
> for (i=0; i<3; i++)
> {
> index = FrmGetObjectIndex(frm, MyFieldId[i]);
> fld = FrmGetObjectPtr(frm, index);
> pFld = FldGetTextPtr(fld);
> len++;
> if (pFld)
> len += StrLen(pFld);
> }
> hRec = DmNewHandle(dbP, len);
> if (!hRec) goto errorExit;
> pRec = MemHandleLock(hRec);
> DmSet(pRec, 0, len, 0);
> offset = 0;
> for (i=0; i<3; i++)
> {
> index = FrmGetObjectIndex(frm, MyFieldId[i]);
> fld = FrmGetObjectPtr(frm, index);
> pFld = FldGetTextPtr(fld);
> len = 1;
> if (pFld)
> {
> len += StrLen(pFld);
> DmWrite(pRec, offset, pFld, len);
> }
> offset += len;
> }
> MemHandleUnlock(hRec);
> if (DmAttachRecord(dbP, MyRecordIndex, hRec, &oldH))
> MemHandleFree(hRec)
> else if (oldH)
> MemHandleFree(oldH);
> }
>
> -bob mckenzie



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

Reply via email to