程序开始时还可以,没有错误,但当执行一段时间(不会很长)后出现错误,请帮我调试
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
PaintBox1: TPaintBox;
PaintBox2: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure PaintBox2Paint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
i,j,k:integer;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
i:=201;
j:=398;
k:=0;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
//Interval=1
i:=i+1;
j:=j-1;
k:=k+1;
Form1.Caption:=IntToStr(k);
PaintBox1.Refresh;
PaintBox2.Refresh;
if i=398 then i:=200+random(198);
if j=201 then j:=398-random(197);
end;procedure TForm1.PaintBox1Paint(Sender: TObject);
var
rgn,rgnb,rgnt,rgn1,rgn2:THandle;
hBrush:THandle;
Rect1,Rect2:TRect;
begin
try
PaintBox2.CleanupInstance;
Rect1.Left:=100;
Rect1.Top:=200;
Rect1.Right:=300;
Rect1.Bottom:=400;
rgnb:=CreateEllipticRgnIndirect(Rect1);
rgnt:=CreateEllipticRgnIndirect(Rect1);
rgn1:=CreateEllipticRgnIndirect(Rect1);
rgn2:=CreateRectRgn(100,200,300,i);
CombineRgn(rgnb,rgn1,rgn2,RGN_DIFF);
CombineRgn(rgnt,rgn1,rgnb,RGN_DIFF);
CombineRgn(rgn,rgnb,rgnt,RGN_AND);
//{
PaintBox1.Canvas.Brush.Color:=clRed;
if not FillRgn(PaintBox1.Canvas.Handle,rgnb,PaintBox1.Canvas.Brush.Handle) then ShowMessage('rgnb Failed');
PaintBox1.Canvas.Brush.Color:=clBlue;
if not FillRgn(PaintBox1.Canvas.Handle,rgnt,PaintBox1.Canvas.Brush.Handle) then ShowMessage('rgnt Failed');
//}
end;procedure TForm1.PaintBox2Paint(Sender: TObject);
var
rgn,rgnb,rgnt,rgn1,rgn2:THandle;
hBrush:THandle;
Rect1,Rect2:TRect;
begin
PaintBox2.CleanupInstance;
Rect1.Left:=100;
Rect1.Top:=200;
Rect1.Right:=300;
Rect1.Bottom:=400;
rgnb:=CreateEllipticRgnIndirect(Rect1);
rgnt:=CreateEllipticRgnIndirect(Rect1);
rgn1:=CreateEllipticRgnIndirect(Rect1);
rgn2:=CreateRectRgn(100,200,300,j);
CombineRgn(rgnb,rgn1,rgn2,RGN_DIFF);
CombineRgn(rgnt,rgn1,rgnb,RGN_DIFF);
CombineRgn(rgn,rgnb,rgnt,RGN_AND);
//{
PaintBox2.Canvas.Brush.Color:=clRed;
if not FillRgn(PaintBox2.Canvas.Handle,rgnb,PaintBox2.Canvas.Brush.Handle) then ShowMessage('rgnb Failed');
PaintBox2.Canvas.Brush.Color:=clBlue;
if not FillRgn(PaintBox2.Canvas.Handle,rgnt,PaintBox2.Canvas.Brush.Handle) then ShowMessage('rgnt Failed');
//}
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
PaintBox1: TPaintBox;
PaintBox2: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure PaintBox2Paint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
i,j,k:integer;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
i:=201;
j:=398;
k:=0;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
//Interval=1
i:=i+1;
j:=j-1;
k:=k+1;
Form1.Caption:=IntToStr(k);
PaintBox1.Refresh;
PaintBox2.Refresh;
if i=398 then i:=200+random(198);
if j=201 then j:=398-random(197);
end;procedure TForm1.PaintBox1Paint(Sender: TObject);
var
rgn,rgnb,rgnt,rgn1,rgn2:THandle;
hBrush:THandle;
Rect1,Rect2:TRect;
begin
try
PaintBox2.CleanupInstance;
Rect1.Left:=100;
Rect1.Top:=200;
Rect1.Right:=300;
Rect1.Bottom:=400;
rgnb:=CreateEllipticRgnIndirect(Rect1);
rgnt:=CreateEllipticRgnIndirect(Rect1);
rgn1:=CreateEllipticRgnIndirect(Rect1);
rgn2:=CreateRectRgn(100,200,300,i);
CombineRgn(rgnb,rgn1,rgn2,RGN_DIFF);
CombineRgn(rgnt,rgn1,rgnb,RGN_DIFF);
CombineRgn(rgn,rgnb,rgnt,RGN_AND);
//{
PaintBox1.Canvas.Brush.Color:=clRed;
if not FillRgn(PaintBox1.Canvas.Handle,rgnb,PaintBox1.Canvas.Brush.Handle) then ShowMessage('rgnb Failed');
PaintBox1.Canvas.Brush.Color:=clBlue;
if not FillRgn(PaintBox1.Canvas.Handle,rgnt,PaintBox1.Canvas.Brush.Handle) then ShowMessage('rgnt Failed');
//}
end;procedure TForm1.PaintBox2Paint(Sender: TObject);
var
rgn,rgnb,rgnt,rgn1,rgn2:THandle;
hBrush:THandle;
Rect1,Rect2:TRect;
begin
PaintBox2.CleanupInstance;
Rect1.Left:=100;
Rect1.Top:=200;
Rect1.Right:=300;
Rect1.Bottom:=400;
rgnb:=CreateEllipticRgnIndirect(Rect1);
rgnt:=CreateEllipticRgnIndirect(Rect1);
rgn1:=CreateEllipticRgnIndirect(Rect1);
rgn2:=CreateRectRgn(100,200,300,j);
CombineRgn(rgnb,rgn1,rgn2,RGN_DIFF);
CombineRgn(rgnt,rgn1,rgnb,RGN_DIFF);
CombineRgn(rgn,rgnb,rgnt,RGN_AND);
//{
PaintBox2.Canvas.Brush.Color:=clRed;
if not FillRgn(PaintBox2.Canvas.Handle,rgnb,PaintBox2.Canvas.Brush.Handle) then ShowMessage('rgnb Failed');
PaintBox2.Canvas.Brush.Color:=clBlue;
if not FillRgn(PaintBox2.Canvas.Handle,rgnt,PaintBox2.Canvas.Brush.Handle) then ShowMessage('rgnt Failed');
//}
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货