First, you increment 'recordindex' before using, so you skip strArray[0] and
potentially write past the allocated array.

Second, since you skipped strArray[0], LstDrawList() tells the list draw
code to dereference a string pointer that is garbage and probably crashes
doing so.

--------------------
Jeff Loucks
Work 425-284-1128 [EMAIL PROTECTED]
Home 253-851-8908 [EMAIL PROTECTED]
Mobile 253-691-8812


-----Original Message-----
From: druid [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 15, 2005 5:27 PM
To: Palm Developer Forum
Subject: Re: Read about it in the SDK.


well I tried to incorporate your ideas intot he snippet
but it still crashes with the same error

Char letter[256];
        Char *p;
        Char **strArray = NULL; //empty array
        Char* strLines = NULL;
        Err err;
        UInt16 recordindex = 0;
        
        StrCopy( letter, "A" );
        err = Open(); // routine to open database
    pForm = FrmGetActiveForm(); // get active form
        lsp1 = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, frmList1));
// get id of list control
        nRecordIndex = DmNumRecords(dbPtr); // number of records
    
        strArray = MemPtrNew(nRecordIndex * sizeof(Char *));

        for(index =0; index < 10; index++) // lets index through database
         {
          h = DmQueryRecord(dbPtr, index); // lets query each record
          p = (Char *) MemHandleLock(h); // lets lock each record
      if( 0 == StrNCaselessCompare( letter, p, 1) ) //compare first letter
of first field
           {
            recordindex++;
                strArray[recordindex] = MemPtrNew(StrLen(p) + 1);
        StrCopy(strArray[recordindex], p);

                //ghStringArray = SysFormPointerArrayToStrings(p, 1);
            //strArray = (Char**) MemHandleLock(ghStringArray);
           }
          MemHandleUnlock(h); // unlock each record 
         }
        LstSetListChoices(lsp1,strArray,recordindex); // clear list
    LstDrawList( lsp1 ); >> HERE is where debugger stops
        err = CloseDB(); 
        return true;
}

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

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

Reply via email to