关于TCanvas的Handle的奇怪问题
C++ Builder 6.0
void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0;i<100;i++)
{
Graphics::TBitmap *bitmap=new Graphics::TBitmap();
bitmap->PixelFormat=pf24bit;
bitmap->Width=256;
bitmap->Height=256;
HDC h=bitmap->Canvas->Handle;
Memo1->Lines->Add("");//如果注释掉此句,则显示结果为OK,否则为HandleAllocated error
if(bitmap->Canvas->HandleAllocated())
{
Memo1->Lines->Add("OK:"+String(i));
}
else
{
Memo1->Lines->Add("HandleAllocated error: "+String(i));
}
delete bitmap;
}
}
在上述代码中,运行结果为HandleAllocated error;如果注释掉则显示结果为OK,百思不得其解。