Thanks for the explanation. I guess I need to rewrite some of my code. I am
only trying to store strings in my database so, I problably should switch
and use and array of characters instead of a Char*. The only reason I was
using Char* in my data structure was the example code I had from a Palm
programming book did it that way.
Or, would it work if I copied the field text into a string and then set my
database.strinP equal to that? Just a thought.
Thanks again for all your help
in article 27672@palm-dev-forum, Aaron Ardiri at [EMAIL PROTECTED] wrote on
10/21/00 1:27 PM:
>
>> Does is make a difference if database.stringP is declared const Char*??
>
> no.. let me explain.
>
>>>> stringP = GetLockedPtr (whateverField);
>>>> if (stringP)
>>>> {
>>>> database.stringP = stringP;
>
> at this point, stringP is valid, as.. it is pointing to a locked
> chunk of memory. both database.stringP and stringP hold the same
> value (ie: point to the same locked chunk of memory)
>
>>>> MemPtrUnlock (stringP);
>
> at this point, the operating system "unlocks" the chunk, and
> the area pointed to by stringP is now invalid. if MemPtrUnlock
> sets it to NULL or whateverm its irrelevant to the issue here.
>
> database.stringP contains a value, and that hasn't changed.
> but.. the minute you try and use it, the operating system
> says "wtf? the handle this pointer is referencing has gone bye-bye"
>
> = crash.
>
>>> In general I think it's advised that you store handles rather than pointers
>>> in database records and even these are questionable since they might be
>>> referred to after a restart when that handle might no longer be allocated
>>> (although since I've never tried to do this I can't state that it's not
>>> valid).
>
> i have done this type of stuff for ages, and.. this is what you do.
> store everything as a Handle.. and *if* you want it.. you do something
> like this:
>
> ...
>
> Char *p = (Char *)MemHandleLock(handle);
> ... use p
> MemPtrUnlock(p);
> ...
>
> the "handle" is what you should have stored somewhere. lock and unlock
> it as you use it - then you wont have any problems.
>
> // az
> [EMAIL PROTECTED]
> http://www.ardiri.com/ <--- free games!
>
>
>
--
Andy Black
[EMAIL PROTECTED] http://www.SpazTheCat.com
Unix is user friendly. It is just picky about who its friends are.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/