hi everyone,
    
Actually i want to populate my ListBox with some of the Values from my 
Database.ex Customer No. and i want this in Form Open Event.
I had opened my Database but initially there are no Records.
I had set a Flag that indicates me that now a record is inserted into database.

so in the FormopenEvent i m checking this Flag and then Populating my ListBox.

I had attached a small snippet with this prblm, that currently i m doing but 
some Memory Problem

How to Do it any suggestions ?


























































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

1.)ProjectDemo(unknown version) just read from memory location 0x00038D5E,
Which is in Memory Manager Data Structures.

These Data Structures include things like the Headers precedings each Block
in a heap,as well as the heap header itself. Such an access usually means
that an application allocated a buffer(possibly  with MemPtrNew) that wasn't
large enough for its purpose.When the application then tries to write the data
to the buffer,it writes off the end of the buffer ,accessing the start of the 
 buffer following it in memory.

2.) ProjectDemo(unknown version) just read from memory location 0x00000028,
Which is in Low Memory. 

"Low Memory" is defined as the first 256 bytes of memory.It should not be 
directly
accessed by applications under any circumstances



static Boolean WelcomeFormHandleEvent(EventType  *event)
{

        Boolean         handled = false;
        FormType        *pForm;
        int i=0;
        char *str;

        switch (event->eType) 
        {
                case frmOpenEvent:
                                                                                
                
                                                        if(WelcomeFlag==true)  
//Set to true when Record is inserted into DB
                                                        {
                                                                
FrmCustomAlert(DBAlert, "WFlag=true info",NULL,NULL);
                                                                FillList();
                                                                
WelcomeFlag=false;
                                                        }
                                                
                                                                pForm = 
FrmGetActiveForm();
                                                                
FrmSetActiveForm (pForm);
                                                                
FrmDrawForm(pForm);
                                                                handled=true;
                                                                break;
                        
                case ctlSelectEvent:
                                                        
switch(event->data.ctlSelect.controlID)
                                                        {
                                                                case 
WForm1AddButton :
                                                                                
                                FrmGotoForm(Form1);
                                                                                
                                Flag_Edit=false;
                                                                                
                                handled=true;
                                                                                
                                break;   
                                                                case 
WFForm1EditButton :
                                                                                
                                Flag_Edit=true;
                                                                                
                                if(WelcomeFlag==true)
                                                                                
                                                Removelist();
                                                                                
                                FrmGotoForm(Form1);
                                                                                
                                break;                                          

                                                                case 
WFForm1DelButton  :
                                                                                
                                
                                                                                
                                break;   
                                                                                
        
                                                                default : break;
                                                        }
                                                
                default : break;
        }       
                        return handled;
}

static void FillList()
{
        FormType        *pForm;
        ListType*   plist;
        UInt16 i;
        UInt16 listIndex; 
        int numChoices = 0;
        
        ListElements = (Char **) MemPtrNew(nbRec1 * sizeof(Char *));    
//nbRec1 contains no. of Records from DB.
        
        for (i=0;i<1;i++) 
        {
                ListElements[i] = (char *) MemPtrNew(10);       
        }
        FrmCustomAlert(DBAlert, "FillList() info",NULL,NULL);                   
        
        SelectRecord(1);

        pForm = FrmGetActiveForm();
        listIndex = FrmGetObjectIndex(pForm, WFForm1ListBox); 
        plist = FrmGetObjectPtr(pForm, listIndex);
        LstSetDrawFunction(plist,(void *)WFForm1ListBoxDraw);
        numChoices = sizeof(ListElements);
        LstSetListChoices(plist,ListElements,numChoices);
        FrmDrawForm(pForm);
}

static void SelectRecord(UInt16 index)
{
        MemHandle                       recH;
        DBRecordTypePtr1        recP;
        UInt16                          attr;
        UInt32                          uniqueID;
        char str[10];
                
                DmOpenDatabaseInfo(db1, &dbID, NULL, NULL, &dbCard, NULL);
                recH = (MemHandle)DmQueryRecord(db1, index);
                if (recH )
                {
                        if (DmRecordInfo(db1, index, &attr, &uniqueID, NULL))
                        {
                                FrmCustomAlert(DBAlert, "Unable to get CNO 
info",NULL,NULL);
                                return;
                        }
                        recP = (DBRecordTypePtr1)MemHandleLock(recH);
                        StrCopy(ListElements[m],recP->ConsumerNo_buf);
                        StrCopy(str,recP->ConsumerNo_buf);
                        m++;
                        FrmCustomAlert(DBAlert, "CNO =",str,NULL);
                }
        
}               

void Removelist()  
{
         UInt16 i;
        if (ListElements) // DataType is Char **
         {
          for (i=0; i<nbRec1; i++)                      //nbRec1 contains no. 
of Records from DB.
         MemPtrFree((MemPtr) ListElements[i]);
         MemPtrFree((MemPtr) ListElements);
        }
}                                       

Reply via email to