关于Access Violation问题,急需解决,望高手指点!!!!!
顽皮小子 2006-06-06 04:49:36 功能:
我从数据库中取得一组数据,然后插入ListView中,同时调用ListView_NewsAdvancedCustomDrawItem事件对ListView中的各条记录进行字体大小、颜色的修改。
问题:
我在运行程序进行以上操作时会不定期出现以下错误:
Project HRR.exe raised exception class EAccessViolation with message 'Access violation at address 004c72cf.Read of address 00c1c00'.Process stopped.Use Step or Run to continue.
望高手解决!
代码如下:
void __fastcall TForm_MainForm::ListView_NewsAdvancedCustomDrawItem(
TCustomListView *Sender, TListItem *Item, TCustomDrawState State,
TCustomDrawStage Stage, bool &DefaultDraw)
{
if (Item == NULL) return;
if (aa == 0) //未读:字体:加粗;
{
Sender->Canvas->Font->Style = TFontStyles()<< fsBold;
if (bb == 1) //重要:字体:红色;
{
Sender->Canvas->Font->Color = clRed;
cc = false;
}
else Sender->Canvas->Font->Color = clBlack; //普通:字体:黑色;
if (cc == true) Item->ImageIndex = 0;
else Item->ImageIndex = 2;
}
else //已读:字体:正常;
{
Sender->Canvas->Font->Style = TFontStyles();
if (bb == 1) //重要:字体:红色;
{
Sender->Canvas->Font->Color = clRed;
cc = false;
}
else Sender->Canvas->Font->Color = clBlack; //普通:字体:黑色;
if (cc == true) Item->ImageIndex = 1;
else Item->ImageIndex = 2;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for (ASQLQuery->First(); !ASQLQuery->Eof; ASQLQuery->Next())
{
TListItem *tempitem = new TListItem(ListView_News->Items);
tempitem->SubItems->Add(数据1);
tempitem->SubItems->Add(数据2);
tempitem->SubItems->Add(数据3);
tempitem->Data = 数据4;
ListView_News->Items->AddItem(tempitem);
}
}