PDA

View Full Version : Problem of IDBRECORD_GetField() or IDISPLAY_DrawText() ?


ngotl
07-21-2002, 03:29 AM
Does any one know there would be different output in the following 2 versions of the codes?The only difference is where I call IDISPLAY_DrawText() to display str1

Version 1:

str1 = NULL;
IDBRECORD_Reset(pIDBRecord);
fType = IDBRECORD_NextField(pIDBRecord, &fName, &len);
str1 = (AECHAR*)IDBRECORD_GetField(pIDBRecord , &fName, &fType, &len);
if(str1 == NULL)
{
return FALSE;
}

/***********following 2 lines are at the end in version 2****/

IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, str1 , -1, 0,100,0, IDF_ALIGN_CENTER | IDF_ALIGN_TOP);

dum = NULL;
// GET THE NEXT FIELD
if((fType=IDBRECORD_NextField(pIDBRecord, &fName, &len))==AEEDB_FT_NONE)
{
return FALSE;
}
dum = (AECHAR*)IDBRECORD_GetField(pIDBRecord, &fName, &fType, &len);
if(dum == NULL)
{
return FALSE;
}


IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, dum, -1, 0,100,0, IDF_ALIGN_CENTER | IDF_ALIGN_BOTTOM);
IDISPLAY_Update(pMe->a.m_pIDisplay);

/***************************************************/


Version 2:



str1 = NULL;
IDBRECORD_Reset(pIDBRecord);
fType = IDBRECORD_NextField(pIDBRecord, &fName, &len);
str1 = (AECHAR*)IDBRECORD_GetField(pIDBRecord , &fName, &fType, &len);
if(str1 == NULL)
{
return FALSE;
}

dum = NULL;
// GET THE NEXT FIELD
if((fType=IDBRECORD_NextField(pIDBRecord, &fName, &len))==AEEDB_FT_NONE)
{
return FALSE;
}
dum = (AECHAR*)IDBRECORD_GetField(pIDBRecord, &fName, &fType, &len);
if(dum == NULL)
{
return FALSE;
}

/*********** These 2 lines were not here in version 1********/
IDISPLAY_ClearScreen(pMe->a.m_pIDisplay);
IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, str1 , -1, 0,100,0, IDF_ALIGN_CENTER | IDF_ALIGN_TOP);


IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, dum, -1, 0,100,0, IDF_ALIGN_CENTER | IDF_ALIGN_BOTTOM);
IDISPLAY_Update(pMe->a.m_pIDisplay);



It turns out the output is different. for version 2, it is correctly output the 2 string of 2 fields but for version 2, str1 becomes the same string as str2 (str1 is assigned by str2)!!!???
I hope my uestion is not confusing, it maybe since i am also so confusing in the midle of the night. sigh. guess it's A good time to firget it.(2:30 am now). Thank you so so much for any help.
LN











:confused:

strychin
08-06-2002, 05:15 PM
Hi, if you check the address returned from the call to IDBRECORD_GetField, you will find that both str1 and str2 are returned with the same address. The DB uses temporary scratch space to return data values in, and you must copy the data out into your own string that you have allocated yourself. The second call to the DB literally writes over the data returned from the first call.

Also, I highly recommend using the commands GetFieldString, GetFieldWord, and GetFieldDWord for extracting data (if you're using BREW v1.1).

Hope this helps.

Sam