I am trying to initilize a popup list in my application. I try
creating a packed string from records in one of my databases to send
to SysFormPointerArrayToStrings. I am not too expereinced with
pointers and the pointer with which I create the packed string is
always empty. I have looked over this code very carefully and after
spendinf a lot of time on it still dont know why. I am all out of
ideas on this so any help will be very much appreciated.
//Global declarations
static MemHandle personnelHandle;
static MemHandle arrayHandle
static CharPtr personnelPtr;
static void PopulatePopUp()
{
int i;
int j;
VoidHand recHandle;
PackedPersonnel *pPersonnel;
FormPtr frm = FrmGetActiveForm();
UInt16 listIndx = FrmGetObjectIndex
(frm,InventoryDetail_Form_Personnel_List);
ListPtr list = FrmGetObjectPtr(frm,listIndx);
int textLen;
int error;
int offset;
char tmp[100];
personnelHandle = MemHandleNew(sizeof (char));
personnelPtr = MemHandleLock(personnelHandle);
OpenDB(&personnelDB, dmModeReadWrite, 0, PersonnelDBName);
if (!personnelDB)
return;
if (personnelDB)
{
for (i = 0; i < personnelCount; i++)
{
recHandle = DmQueryRecord(personnelDB,i);
if (recHandle == 0)
return;
pPersonnel = MemHandleLock(recHandle);
StrCopy((char*)&tmp,pPersonnel->name);
textLen = StrLen(tmp);
error = MemPtrResize(personnelPtr, textLen + 1 +
offset);
ErrFatalDisplayIf (error,"Ran out of memory reading
personnel, exiting...");
for (j = 0; j < textLen; j++ )
{
personnelPtr[offset + j] = tmp[j];
}
offset += textLen;
personnelPtr[offset++] = 0;
MemHandleUnlock(recHandle);
}
}
//HERE I NOTICE THAT personnelPtr IS NOT POINTING TO ANYTHING!!
arrayHandle = SysFormPointerArrayToStrings
(personnelPtr,personnelCount);
LstSetListChoices(list, MemHandleLock(personnelPtrHandle),
personnelCount);
//CtlSetLabel(FrmGetObjectPtr(frm,triggerIndx), "Personnel");
DmCloseDatabase(personnelDB);
FrmDrawForm(frm);
LstSetDrawFunction(list,DrawPersonnelList);
}
//I free the globals here
static void StopApplication(void) {
MemHandleFree(personnelHandle);
MemHandleFree(personnelPtrHandle);
FrmCloseAllForms();
} // StopApplication
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/