Try it this way:
typedef struct {
long value;
VoidHand text;
} MyType;
MyType MyArray[10];
MyArray[0].value = 5;
MyArray[0].text = MemHandleNew(StrLen("Bob") + 1);
CharPtr s = MemHandleLock(MyArray[0].text);
StrCopy(s, "Bob");
MemHandleUnlock(MyArray[0].text);
...
VoidHand h = FldGetTextHandle(someField);
CharPtr s1 = MemHandleLock(h);
CharPtr s2 = MemHandleLock(MyArray[0].text);
StrCopy(s1, s2);
MemHandleUnlock(h);
MemHandleUnlock(MyArray[0].text);
Of course, you should also make sure that the handle returned by
FldGetTextHandle is large enough to hold the string you're copying into it.
-- Keith Rollin
-- Palm OS Emulator engineer
Jason Garrett <[EMAIL PROTECTED]> on 06/16/99 09:21:28 PM
Please respond to [EMAIL PROTECTED]
Sent by: Jason Garrett <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (Keith Rollin/HQ/3Com)
Subject: When to lock a chunk?
I have a programming dilemma....
I have defined an array
typedef struct {
long value;
CharPtr text;
} MyType;
MyType MyArray[10];
To set the text property, I ...
MyArray[0].value = 5;
VoidHand h = MemHandleNew(StrLen("Bob") + 1);
CharPtr s = MemHandleLock(h);
StrCopy(s, "Bob");
MyArray[0].text = s;
MemHandleUnlock(h);
Now, I get away with that. But, when I want to use 'text' again later...
VoidHand h = FldGetTextHandle(someField);
CharPtr s = MemHandleLock(h);
StrCopy(s, MyArray[0].text); <<<<<<<<<<<<< Error: Accessing unlocked
memory
MemHandleUnlock(h);
I get the indicated error when using POSE (which is great, because it picks
up errors that
my have gone undetected!)
Can someone please correct me, and get me over this problem. There is a
strong chance that
I have taken a poor approach to this, and there is a much better and correct
method.
Please! and Thanks!
Jason