我画了一个表格在表格的每个单元格填充了图片用于区别设备在线和报警情况。可是状态改变多次后图片突然消失。
procedure TfrmMain.PaintCanvas(iIndex : Integer;pic : TPicture);
var
rect : TRect ;
fontHeight : Integer;
fontPoint : TPoint ;
preBrush : TBrush ;
preFont : TFont ;
grp : TBitmap ;
tmpImg : TImage ;
begin
rect.Left := 0 ;
rect.Top := 0 ;
rect.Right := monitorList[iIndex].imgCtl.Width ;
rect.Bottom := monitorList[iIndex].imgCtl.Height ; tmpImg := TImage.Create(Self);
tmpImg.Width := monitorList[iIndex].imgCtl.Width ;
tmpImg.Height := monitorList[iIndex].imgCtl.Height ;
//tmpImg.Picture.LoadFromFile(bmpFile);
tmpImg.Picture.Assign(pic); tmpImg.Canvas.Brush.Style := bsClear ;
tmpImg.Canvas.Font.Size := 10 ;
tmpImg.Canvas.Font.Style := [fsBold] ;
if monitorList[iIndex].MouseIn then
tmpImg.Canvas.Font.Color := clWhite
else
tmpImg.Canvas.Font.Color := clBlack ;
fontHeight := tmpImg.Canvas.TextHeight(monitorList[iIndex].cMonitorName) ; fontPoint.Y := (monitorList[iIndex].imgCtl.Height-fontHeight) div 2 ;
fontPoint.X := 23 ;
Canvas.Lock;
tmpImg.Canvas.TextOut(fontPoint.X, fontPoint.Y, monitorList[iIndex].cMonitorName ); monitorList[iIndex].imgCtl.Canvas.CopyRect(monitorList[iIndex].imgCtl.ClientRect,tmpImg.Canvas,tmpImg.ClientRect);
Canvas.Unlock;
tmpImg.Free ;
end;我这个函数为什么图片会消失掉procedure TfrmMain.DrawImage(iIndex : Integer);
begin
if monitorList[iIndex].MouseIn = TRUE then
begin
if monitorList[iIndex].state = ST_ONLINE then //在线
//PaintCanvas(iIndex,'.\bmp\Green_2.bmp')
PaintCanvas(iIndex,pic_Green_2)
else if monitorList[iIndex].state = ST_OFFLINE then//不在线
//PaintCanvas(iIndex,'.\bmp\Gray_2.bmp')
PaintCanvas(iIndex,pic_Gray_2)
else if monitorList[iIndex].state = ST_ALARM then//报警
//PaintCanvas(iIndex,'.\bmp\Red_2.bmp') ;
PaintCanvas(iIndex,pic_Red_2) ;
end
else
begin
if monitorList[iIndex].state = ST_ONLINE then //在线
//PaintCanvas(iIndex,'.\bmp\Green_1.bmp')
PaintCanvas(iIndex,pic_Green_1)
else if monitorList[iIndex].state = ST_OFFLINE then//不在线
//PaintCanvas(iIndex,'.\bmp\Gray_1.bmp')
PaintCanvas(iIndex,pic_Gray_1)
else if monitorList[iIndex].state = ST_ALARM then//报警
PaintCanvas(iIndex,pic_Red_2) ;
end;
end;procedure showAlarmThread.Execute;
var
i : Integer;
begin
while True do
begin
for i:=0 to frmMain.iCount*frmMain.bs-1 do
begin
if Not Terminated then
begin
if (frmMain.Monitorlist[i].state = ST_ALARM) And (frmMain.Monitorlist[i].MouseIn = FALSE) then
frmMain.DrawImage(i);
end
else
break;
end;
Sleep(500);
end;
end;这个是报警时触发的线程
procedure TfrmMain.PaintCanvas(iIndex : Integer;pic : TPicture);
var
rect : TRect ;
fontHeight : Integer;
fontPoint : TPoint ;
preBrush : TBrush ;
preFont : TFont ;
grp : TBitmap ;
tmpImg : TImage ;
begin
rect.Left := 0 ;
rect.Top := 0 ;
rect.Right := monitorList[iIndex].imgCtl.Width ;
rect.Bottom := monitorList[iIndex].imgCtl.Height ; tmpImg := TImage.Create(Self);
tmpImg.Width := monitorList[iIndex].imgCtl.Width ;
tmpImg.Height := monitorList[iIndex].imgCtl.Height ;
//tmpImg.Picture.LoadFromFile(bmpFile);
tmpImg.Picture.Assign(pic); tmpImg.Canvas.Brush.Style := bsClear ;
tmpImg.Canvas.Font.Size := 10 ;
tmpImg.Canvas.Font.Style := [fsBold] ;
if monitorList[iIndex].MouseIn then
tmpImg.Canvas.Font.Color := clWhite
else
tmpImg.Canvas.Font.Color := clBlack ;
fontHeight := tmpImg.Canvas.TextHeight(monitorList[iIndex].cMonitorName) ; fontPoint.Y := (monitorList[iIndex].imgCtl.Height-fontHeight) div 2 ;
fontPoint.X := 23 ;
Canvas.Lock;
tmpImg.Canvas.TextOut(fontPoint.X, fontPoint.Y, monitorList[iIndex].cMonitorName ); monitorList[iIndex].imgCtl.Canvas.CopyRect(monitorList[iIndex].imgCtl.ClientRect,tmpImg.Canvas,tmpImg.ClientRect);
Canvas.Unlock;
tmpImg.Free ;
end;我这个函数为什么图片会消失掉procedure TfrmMain.DrawImage(iIndex : Integer);
begin
if monitorList[iIndex].MouseIn = TRUE then
begin
if monitorList[iIndex].state = ST_ONLINE then //在线
//PaintCanvas(iIndex,'.\bmp\Green_2.bmp')
PaintCanvas(iIndex,pic_Green_2)
else if monitorList[iIndex].state = ST_OFFLINE then//不在线
//PaintCanvas(iIndex,'.\bmp\Gray_2.bmp')
PaintCanvas(iIndex,pic_Gray_2)
else if monitorList[iIndex].state = ST_ALARM then//报警
//PaintCanvas(iIndex,'.\bmp\Red_2.bmp') ;
PaintCanvas(iIndex,pic_Red_2) ;
end
else
begin
if monitorList[iIndex].state = ST_ONLINE then //在线
//PaintCanvas(iIndex,'.\bmp\Green_1.bmp')
PaintCanvas(iIndex,pic_Green_1)
else if monitorList[iIndex].state = ST_OFFLINE then//不在线
//PaintCanvas(iIndex,'.\bmp\Gray_1.bmp')
PaintCanvas(iIndex,pic_Gray_1)
else if monitorList[iIndex].state = ST_ALARM then//报警
PaintCanvas(iIndex,pic_Red_2) ;
end;
end;procedure showAlarmThread.Execute;
var
i : Integer;
begin
while True do
begin
for i:=0 to frmMain.iCount*frmMain.bs-1 do
begin
if Not Terminated then
begin
if (frmMain.Monitorlist[i].state = ST_ALARM) And (frmMain.Monitorlist[i].MouseIn = FALSE) then
frmMain.DrawImage(i);
end
else
break;
end;
Sleep(500);
end;
end;这个是报警时触发的线程
解决方案 »
- grid中定位行的问题
- SHFileOperation批量删除文件问题
- delphi怎么进行强制类型转换啊我
- 关于图片记录得读取
- 請教大家各種按鍵的ASCII對照表
- 关于FLASH控件的简单而又高分之问题!!
- 我用LoadLibrary调用一DLL并显示其中的非模式窗体,那么该如何合理的释放掉系统资源,即在所有非模式窗体关闭后FeeLibrary?
- 保存Icon的DLL,可以保存为1,4,8,16,24,32位
- 小弟菜鸟,二十分,谢谢!
- 调用ComboBox的Text值作为数据库名称查询数据
- 求助Remobjects的TDAMemDataTale的Locate无法定位记录的问题
- 求教不包含某字符串的正则表达式该怎么写
加上同步试一试
var
rect : TRect ;
fontHeight : Integer;
fontPoint : TPoint ;
preBrush : TBrush ;
preFont : TFont ;
grp : TBitmap ;
tmpImg : TImage ;
begin
tmpImg := TImage.Create(Self);
try
rect.Left := 0 ;
rect.Top := 0 ;
rect.Right := monitorList[iIndex].imgCtl.Width ;
rect.Bottom := monitorList[iIndex].imgCtl.Height ; tmpImg.Width := monitorList[iIndex].imgCtl.Width ;
tmpImg.Height := monitorList[iIndex].imgCtl.Height ;
//tmpImg.Picture.LoadFromFile(bmpFile);
tmpImg.Picture.Assign(pic); tmpImg.Canvas.Brush.Style := bsClear ;
tmpImg.Canvas.Font.Size := 10 ;
tmpImg.Canvas.Font.Style := [fsBold] ;
if monitorList[iIndex].MouseIn then
tmpImg.Canvas.Font.Color := clWhite
else
tmpImg.Canvas.Font.Color := clBlack ;
fontHeight := tmpImg.Canvas.TextHeight(monitorList[iIndex].cMonitorName) ; fontPoint.Y := (monitorList[iIndex].imgCtl.Height-fontHeight) div 2 ;
fontPoint.X := 23 ;
Canvas.Lock;
try
tmpImg.Canvas.TextOut(fontPoint.X, fontPoint.Y, monitorList[iIndex].cMonitorName ); monitorList[iIndex].imgCtl.Canvas.CopyRect(monitorList[iIndex].imgCtl.ClientRect,tmpImg.Canvas,tmpImg.ClientRect);
finally
Canvas.Unlock;
end;
finally
tmpImg.Free ;
end;
end;具体没看出什么原因,加了些保护。
还有就是操作主线程界面的东西的时候,我们一般使用同步的方法,而不是直接使用Execute方法来写。
参考多线程编程同步部分!