(My message didn't appear on the server somehow, so I'm reposting it. Sorry if
you get it twice)
Hi,
still my first Palm app, sorry for asking newbie questions.
I use the below function parse records in a given direction and to find a
substring within the record. It works fine for some hundred records but then
lCurrentRecTextH gets NULL, I guess the heap is full then.
I use MemHandleLock and MemHandleUnlock in every loop, I thought this would
enable Palm to reallocate memory. What am I doing wrong?
static MemHandle QueryNextInFilter (UInt16 *recordNum, Char *filterText, Int16
direction)
{
MemHandle recordH;
MemoDBRecordPtr memoRecP;
MemHandle lCurrentRecTextH;
MemHandle lFilterTextH;
Char * lCurrentRecTextP; // Lowercase text of Current record
Char * lFilterTextP; // Lowercase text of keyword to seacrh in record
UInt16 noteLen;
if (filterText == NULL)
{
recordH = DmQueryRecord (MemoDB, *recordNum);
}
else
{
lFilterTextH = MemHandleNew (StrLen(filterText)+1);
lFilterTextP = MemHandleLock (lFilterTextH);
StrCopy(lFilterTextP, filterText);
StrToLower (lFilterTextP, lFilterTextP);
while (true)
{
if ((*recordNum & 0x000f) == 0 && // every 16th
record
EvtSysEventAvail(true))
{
// Stop the search process
break;
}
recordH = DmQueryRecord (MemoDB, *recordNum);
// No more records
if (! recordH)
{
break;
}
memoRecP = MemHandleLock (recordH);
if (&(memoRecP->note) != NULL)
{
noteLen = StrLen(&(memoRecP->note))+1;
lCurrentRecTextH = MemHandleNew (noteLen);
if (lCurrentRecTextH)
{
lCurrentRecTextP = MemHandleLock
(lCurrentRecTextH);
StrCopy(lCurrentRecTextP,
&(memoRecP->note));
StrToLower (lCurrentRecTextP,
lCurrentRecTextP);
if (StrStr (lCurrentRecTextP,
lFilterTextP))
{
MemHandleUnlock
(lCurrentRecTextH);
MemHandleUnlock (recordH);
break;
}
MemHandleUnlock (lCurrentRecTextH);
}
}
MemHandleUnlock (recordH);
*recordNum += direction;
}
MemHandleUnlock(lFilterTextH);
}
return ((MemHandle)recordH);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/