W
woodcutter
Unregistered / Unconfirmed
GUEST, unregistred user!
我要编一个简单的多线程绘图程序,我用delphi自带的thread object创建如下
我在主窗口中放了三个paintbox,一个button,
button的onclick事件如下
procedure TForm1.Button1Click(Sender: TObject);
begin
paintclock.create(paintbox2) ;
paintclock.create(paintbox1) ;
paintclock.create(paintbox3) ;
end;
多线程单元如下
unit Unit2;
interface
uses
Classes,Graphics,windows, ExtCtrls;
type
paintclock = class(TThread)
private
fbox:tpaintbox;
a:integer;
protected
procedure drawlines;
procedure Execute;
override;
public
constructor create(box:tpaintbox);
end;
implementation
procedure paintclock.drawlines;
begin
with fboxdo
begin
while a<=100do
begin
canvas.pen.color:=clred;
//一根木棍绕着paintbox的中点转动
canvas.moveto(33+round(33*sin(5*a*3.14/180)),33-round(33*cos(5*a*3.14/180)));
canvas.lineto(33-round(33*sin(5*a*3.14/180)),33+round(33*cos(5*a*3.14/180)));
a:=a+1;
sleep(100);
{if terminated then
exit;}
end;
end;
end;
constructor paintclock.create(box:tpaintbox);
begin
fbox:=box;
freeonterminate:=true;
inherited create(false);
end;
procedure paintclock.Execute;
begin
synchronize(drawlines);
end;
end.
请问,这个程序能够实现真正的多线程吗?如有不妥,应该怎么改正,谢谢!
我在主窗口中放了三个paintbox,一个button,
button的onclick事件如下
procedure TForm1.Button1Click(Sender: TObject);
begin
paintclock.create(paintbox2) ;
paintclock.create(paintbox1) ;
paintclock.create(paintbox3) ;
end;
多线程单元如下
unit Unit2;
interface
uses
Classes,Graphics,windows, ExtCtrls;
type
paintclock = class(TThread)
private
fbox:tpaintbox;
a:integer;
protected
procedure drawlines;
procedure Execute;
override;
public
constructor create(box:tpaintbox);
end;
implementation
procedure paintclock.drawlines;
begin
with fboxdo
begin
while a<=100do
begin
canvas.pen.color:=clred;
//一根木棍绕着paintbox的中点转动
canvas.moveto(33+round(33*sin(5*a*3.14/180)),33-round(33*cos(5*a*3.14/180)));
canvas.lineto(33-round(33*sin(5*a*3.14/180)),33+round(33*cos(5*a*3.14/180)));
a:=a+1;
sleep(100);
{if terminated then
exit;}
end;
end;
end;
constructor paintclock.create(box:tpaintbox);
begin
fbox:=box;
freeonterminate:=true;
inherited create(false);
end;
procedure paintclock.Execute;
begin
synchronize(drawlines);
end;
end.
请问,这个程序能够实现真正的多线程吗?如有不妥,应该怎么改正,谢谢!