程序死了!(50分)

  • 主题发起人 主题发起人 fl0603
  • 开始时间 开始时间
F

fl0603

Unregistered / Unconfirmed
GUEST, unregistred user!
我编写了一个程序,是两个相似图形的交替出现,形成动画,代码如下:
type
tanimthread=class(tthread)
private
b:tbitmap;
procedure drawanimpic;
protected
procedure execute;override;
end;
var
Form1: TForm1;
tleft,ttop:integer;
dir:integer;
index:integer;

implementation

{$R *.dfm}
procedure tanimthread.drawanimpic;
begin
bitblt(form1.Canvas.Handle,tleft,ttop,200,200,b.Canvas.Handle,0,0,srccopy);
end;


procedure tanimthread.execute;
var
run:boolean;
begin
b:=tbitmap.Create;
b.Width:=200;
b.Height:=200;
b.Canvas.Pen.color:=clbtnface;
b.Canvas.Brush.Color:=clbtnface;
b.Canvas.Rectangle(0,0,200,200);
run:=true;
while run do
begin
b.Canvas.Rectangle(0,0,200,200);
form1.ImageList1.Draw(b.Canvas,1,1,index);
synchronize(drawanimpic);
sleep(20);
end;
b.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
index:=0;
tleft:=10;
ttop:=10;
imagelist1.Draw(form1.Canvas,tleft,ttop,index);
animthread:=tanimthread.Create(false);
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
vk_left:
begin
if (tleft>10) then
dec(tleft);
index:=index xor 1;
dir:=3;
end;
vk_right:
begin
if (tleft+200)<(width-30) then
inc(tleft);
index:=index xor 1;
dir:=1;
end;
end;
end;

end.
当我按下左键或者右键后,程序运行只能维持几秒,以后就不再运行了,就像死了一样,请问这是怎么回事?如何解决?
 
把所有和tbitmap有关的操作都放在synchronize的过程里试试。
 
后退
顶部