I don't know if there is any more error, but the obvious one is:

You got the pointer (recPtr) to the record by using MemHandleLock in the while
loop, but in the following code you unlocked that handle!  After that, the
pointer may not point to whhere the data was.

You probably don't want to keep it locked...One solution is to allocate space
dynamically using MemPtrNew and COPY all the strings to it.

Good luck.

Max
--- Gonzalo Piano <[EMAIL PROTECTED]> wrote:
> I want to read the data from a database and set them in a list in a 
> dynamic way, I mean without caring how many fields that database 
> has. The code I�m using is:
> 
> static void FillList(DmOpenRef Base, ListType *lst)
> {
>       char **itemList;
>       char * recPtr = NULL;
>       MemHandle recHandle;
>       int probe, numOfRecords;
> 
>       numOfRecords = DmNumRecords(Base);
>       
>       probe = 0;
>       itemList = (char **) MemPtrNew(numOfRecords * sizeof(char*));
>       gListChoices = itemList;
>       gListNumItems = numOfRecords;   
>       
>       while (numOfRecords > probe){
>               
>               recHandle = DmGetRecord(Base, probe);
>               if (recHandle == NULL) 
>                       ErrDisplay ("ERROR");
>       
>               recPtr    = MemHandleLock(recHandle);
>                        itemList[probe] = recPtr;
>                       
>             DmReleaseRecord (Base, probe, true);
>     
>               probe++;
>               
>           if (recHandle)
>               MemHandleUnlock(recHandle);
>       }
> 
>       LstSetListChoices(lst, itemList, numOfRecords);
> }
> 
> 
> Code in frmOpenEvent (MainFormHandleEvent):
> 
> 
>       list = (ListType *)FrmGetObjectPtr (frmP,
> FrmGetObjectIndex(frmP, MainList));
>       FillList(UbicDB, list);
>       LstSetSelection(lista, 0);
> 
> 
> Code in frmCloseEvent (MainFormHandleEvent):
> 
> 
>       if (gListChoices) {
>               for (i=0; i<gListNumItems; i++){
>                       MemPtrFree((MemPtr) gListChoices[i]);
>                       MemPtrFree((MemPtr) gListChoices);
>                       gListChoices=0;
>               }
>      }        
> 
> When I execute the program only the first field appears and nothing 
> more.
> 
> PD: When I create the list I put 1 visible item (I can't put more 
> because the CodeWarrior Linker says that no fields exist for the 
> list, this value can�t be bigger than 1 and my idea is to creat the 
> fields at  runtime) so I don�t put any field.
> 
> Thanks.
> 
> ---
> Gonzalo Piano.
> [EMAIL PROTECTED]
> 
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please
> see http://www.palmos.com/dev/tech/support/forums/


__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.yahoo.com

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

Reply via email to