提示 Canvas don 't allow drawing错误

luo_342815 2010-06-21 03:24:38
这个错误如何解决?这个错误有的时候发生得早,有的时候过一端时间发生。发生以后就不工作了。编译又没错。
 For i:=0 to 200+lineh*10 do begin  //循环显示相关信息   /
if PThreadStart then//PThreadStart =true;
begin
if i=150 then sleep(3000);

main.Paintbox1.Canvas.Lock;

main.Paintbox1.Canvas.TextOut(5,155+-i,'最新进出场站公交信息:');

main.Paintbox1.Canvas.TextOut(10,155+lineh*2-i,'车辆信息:');

main.Paintbox1.Canvas.TextOut(300,155+lineh*2-i,'驾驶员信息:');

main.Paintbox1.Canvas.TextOut(10,155+lineh*4-i,'车牌:'+Plate);

main.Paintbox1.Canvas.TextOut(300,155+lineh*4-i,'姓名:'+WorkerName+' 性别:'+Sex+' 工号:'+WorkID);

main.Paintbox1.Canvas.TextOut(10,155+lineh*6-i,'车型:'+BusStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*6-i,'年龄:'+Age+' 工龄:'+Seniority);

main.Paintbox1.Canvas.TextOut(10,155+lineh*8-i,'时间:'+OperateTime+' 状态:'+OperateStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*8-i,'联系电话:'+Telephone);

main.Paintbox1.Canvas.TextOut(10,155+lineh*9-i,' ');
sleep(20);

end;
end
else
begin
main.Paintbox1.Invalidate;

exit;
end;
end;

...全文
179 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
luo_342815 2010-06-22
  • 打赏
  • 举报
回复
谢谢大家。
nanchangfantasy 2010-06-22
  • 打赏
  • 举报
回复
delphi线程是不受保护的,你要坚信用synchronize,或则用criticalsection来同步
否则肯定会有很多莫名的隐患.
只要把这段代码放到synchronize执行,该能没事的.
将如下放到synchronize
main.Paintbox1.Canvas.TextOut(5,155+-i,'最新进出场站公交信息:');

main.Paintbox1.Canvas.TextOut(10,155+lineh*2-i,'车辆信息:');

main.Paintbox1.Canvas.TextOut(300,155+lineh*2-i,'驾驶员信息:');

main.Paintbox1.Canvas.TextOut(10,155+lineh*4-i,'车牌:'+Plate);

main.Paintbox1.Canvas.TextOut(300,155+lineh*4-i,'姓名:'+WorkerName+' 性别:'+Sex+' 工号:'+WorkID);

main.Paintbox1.Canvas.TextOut(10,155+lineh*6-i,'车型:'+BusStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*6-i,'年龄:'+Age+' 工龄:'+Seniority);

main.Paintbox1.Canvas.TextOut(10,155+lineh*8-i,'时间:'+OperateTime+' 状态:'+OperateStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*8-i,'联系电话:'+Telephone);

main.Paintbox1.Canvas.TextOut(10,155+lineh*9-i,' ');
main.Paintbox1.Canvas.Unlock ;
cngoodman 2010-06-21
  • 打赏
  • 举报
回复
main.Paintbox1.Canvas.Unlock 呢?
taxi 2010-06-21
  • 打赏
  • 举报
回复
把while里面的代码放到synchronize中,sleep(1000)放在while循环里面。
taxi 2010-06-21
  • 打赏
  • 举报
回复
要放到synchronize中画,把 sleep(1000)放在while循环里面。
luo_342815 2010-06-21
  • 打赏
  • 举报
回复
这个是整个线程函数。不用synchronize的好像运行还可以,就是不大稳定。用了synchronize就卡在那里了。加了 application.ProcessMessages 效果也不提高不了多少。象这种一直要修改界面的情况,用synchronize不大合适吧?

procedure PaintThread.Execute;
var lineh,i:integer;
begin
ReRead:=true;
sleep(1000);
while PThreadStart do
begin

if ReRead then
begin
with DM.DM1.AQ3 do
begin
close;
sql.clear;
sql.add('select top 1 ID,WorkID,WorkerEPC,WorkerName,WorkerAge,WorkerTelephone,'+
'WorkerSeniority,WorkerSex,Plate,BusEPC,BusYearUsed,BusStyle,OperateTime,OperateStyle from IOMessage order by ID DESC');
open;
if recordcount<>0 then
begin
Plate:=fieldbyname('Plate').AsString;
BusStyle:=fieldbyname('BusStyle').AsString;
YearUsed:=fieldbyname('BusYearUsed').AsString;
OperateTime:=fieldbyname('OperateTime').AsString;
OperateStyle:=fieldbyname('OperateStyle').AsString;

WorkID:=fieldbyname('WorkID').AsString;
WorkerName:=fieldbyname('WorkerName').AsString;
Age:=fieldbyname('WorkerAge').AsString;
Sex:=fieldbyname('WorkerSex').AsString;
Seniority:=fieldbyname('WorkerSeniority').AsString;
Telephone:=fieldbyname('WorkerTelephone').AsString;
end;
end;
ReRead:=false;
end;
lineh:=main.Paintbox1.Canvas.TextHeight('0'); //求字符的高度
For i:=0 to 200+lineh*10 do begin //循环显示相关信息 /
if PThreadStart then
begin
if i=150 then sleep(3000);
main.Paintbox1.Canvas.TextOut(5,155+-i,'最新进出场站公交信息:');
main.Paintbox1.Canvas.TextOut(10,155+lineh*2-i,'车辆信息:');

main.Paintbox1.Canvas.TextOut(300,155+lineh*2-i,'驾驶员信息:');

main.Paintbox1.Canvas.TextOut(10,155+lineh*4-i,'车牌:'+Plate);

main.Paintbox1.Canvas.TextOut(300,155+lineh*4-i,'姓名:'+WorkerName+' 性别:'+Sex+' 工号:'+WorkID);

main.Paintbox1.Canvas.TextOut(10,155+lineh*6-i,'车型:'+BusStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*6-i,'年龄:'+Age+' 工龄:'+Seniority);

main.Paintbox1.Canvas.TextOut(10,155+lineh*8-i,'时间:'+OperateTime+' 状态:'+OperateStyle);

main.Paintbox1.Canvas.TextOut(300,155+lineh*8-i,'联系电话:'+Telephone);

main.Paintbox1.Canvas.TextOut(10,155+lineh*9-i,' ');
//
Delay(0,1);
end
else
begin
main.Paintbox1.Invalidate;

exit;
end;
end;
end;
end;
luo_342815 2010-06-21
  • 打赏
  • 举报
回复
果然用了synchronize主程序就干不了别的了。
luo_342815 2010-06-21
  • 打赏
  • 举报
回复
synchronize是把这个线程代入到主线程吗?
我这个线程是一直用来滚动字幕的,如果放到主线程那不是响应不了别的事件了。

而且我现在还不懂synchronize怎么用!
Harryfin 2010-06-21
  • 打赏
  • 举报
回复
放在synchronize里面调用
luo_342815 2010-06-21
  • 打赏
  • 举报
回复
跟这个贴问题很类似,http://topic.csdn.net/t/20041019/15/3470509.html
但是没解决!
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle

16,746

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧