Hi,
My code for searching & adding records to the list.

static void SearchRecord() 
{ 
UInt16 i = 0; 
MemHandle memH; 
char str[10]; 
DBBrandPtr recP; 
UInt16 count = 0; 
Char ** itemList = 0; 
FormPtr frmP = FrmGetActiveForm(); 
ListType *list; 

itemList = (Char **)MemPtrNew(nbRec * sizeof(Char *)); 
StrCopy(str,GetTextField(FrmViewForm,frmViewTxtSrNoField)); 
//search the record 
curRec = 0; 
do{ 
memH = (MemHandle)DmQueryRecord(db,curRec); 
if(memH == NULL) 
{ 
FrmAlert(NoMemoryAllocatedAlert); 
return; 
} 
recP = (DBBrandPtr)MemHandleLock(memH); 
ErrFatalDisplayIf(!recP, "recP fail"); 
char name[15]; 
if(StrStr(recP->BrandName,str) != NULL) 
{ 
count++; 
StrCopy(name,recP->BrandName); 
UInt16 len = StrLen(name); 
itemList[i] = (Char *)MemPtrNew(len+1); StrCopy(itemList[i],name); // does not work 
//MemPtrFree(itemList[i]); 
} 
MemHandleUnlock(memH); 
DmReleaseRecord(db,curRec,false); 
curRec++; 
i++; 
}while(i < nbRec); 
// draw and display the list 

LstNewList((void**)&frmP,1,75,34,35,50,stdFont,6,2); 
MemPtrResize(itemList,count * sizeof(Char *)); 
list = (ListType*)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, UInt16)1)); // 1 is 
the list ID 
LstSetListChoices(list,itemList, count); 
LstPopupList(list); 
MemPtrFree(itemList); 
} 


What is wrong with this code? 

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

Reply via email to