Hi All,
       I'm trying to use the callback function with the list(LstSetDrawFunction) to 
create a dynamic list. Everything compiles successfully, but during debugging, I only 
saw the name of the first student appearing on the dynamic list like this:

Alex
Alex //should be other name
Alex //should be other name
Alex //should be other name
Alex //should be other name
Alex //should be other name
Alex //should be other name

... until the end of the list. Thus, I use a (for) loop in the call back function and 
I obtain the same as the above except this time, it's the last student's name =( 
I'm sorry for asking such a "newbie" question but I hope someone could tell me what 
actually is wrong or anything I'm missing.

typedef struct {
  Int32   studentID;
  const char *Name;
  const char *Class;
  const char *Gender;
} Student;

typedef struct {
  Int32 studentID;
  char  Name[1];  // actually may be longer than 1

} PackedStudent;

static void DrawCharsToFitWidth(const Char *s, RectanglePtr r)
{
  Int16 stringLength = StrLen(s);
  Int16 pixelWidth = r->extent.x;
  Boolean truncate;
  
  // FntCharsInWidth will update stringLength to the 
  // maximum without exceeding the width
  FntCharsInWidth(s, &pixelWidth, &stringLength, &truncate);
  WinDrawChars(s, stringLength, r->topLeft.x, r->topLeft.y);
}

//Call back Function
static void DrawStudentInList(Int16 itemNumber, RectanglePtr bounds, Char **txt)
{
#pragma unused(txt)
#pragma unused(itemNumber)
        MemHandle h;
        PackedStudent *psr;
        UInt16 NumRecors;
        
        ListPtr list = (ListPtr) GetObjectFromActiveForm(MainStudentsNameList);
        
        NumRecors = DmNumRecords(gDatabase);

        /*THIS IS THE FOR LOOP THAT I'VE ADD*/
        for (indx=0; indx <NumRecors; indx++)
        {
        
        h = DmQueryRecord(gDatabase, indx);
        psr = (PackedStudent *) MemHandleLock(h);
        
        
        DrawCharsToFitWidth(psr->Name, bounds);
        MemHandleUnlock(h);
        }
}       

// Dynamic Function
static void FillListWithName(ListType *lst)
{

const int kCardNumber = 0;
const char *kTag = "test-DB";
Err     err;  
LocalID DbID;
ListPtr list;
FormPtr frmP;
UInt16 NumRecor;

DbID = DmFindDatabase(kCardNumber, kTag);
        if(!DbID)
                err = DmGetLastErr;     
        else {
                gDatabase= DmOpenDatabase(kCardNumber, DbID, dmModeReadOnly);
                 if(!gDatabase)
                         err = DmGetLastErr;
                }

list = (ListPtr) GetObjectFromForm(frmP, MainStudentsNameList);
   
NumRecor = DmNumRecords(gDatabase);
                         
LstSetDrawFunction(list, DrawStudentInList);
LstSetListChoices(list, NULL, (Int16) NumRecor);
LstSetSelection(list, 0);

}

Sorry for the long post.

Many Thanks
Regards
Lauren




____________________________________________________________
Get 250 full-color business cards FREE right now!
http://businesscards.lycos.com 

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

Reply via email to