怎样使程序正当特效显示图像时立即终止并释放占用的全部资源(100)

  • 主题发起人 主题发起人 sghff110
  • 开始时间 开始时间
S

sghff110

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.BitBtn1Click(Sender: TObject);var i:integer; sourcebmp:Tbitmap; begin sourcebmp:=Tbitmap.Create; sourcebmp.LoadFromFile('e:/sunrise.bmp'); try for i:=0 to sourcebmp.Height do begin stretchblt(image1.Canvas.Handle ,0,0, image1.Width ,i, sourcebmp.Canvas.Handle,0,0, sourcebmp.Width,i,srccopy);// image1.Refresh ; sleep(3); Application.ProcessMessages; end; finally sourcebmp.Free ; end;end;上述代码实现了图像的下伸效果。能否在它尚未完成特效显示时点击button2让其即刻终止并退出?
 
在循环里加个判断变量
 
设全局变量i,j,用如下结构~~j:=sourcebmp.Height;reapt stretchblt(image1.Canvas.Handle ,0,0, image1.Width ,i, sourcebmp.Canvas.Handle,0,0, sourcebmp.Width,i,srccopy); inc(i);until i=sourcebmp.Height;*********************************************************procedure TForm1.Button2Click(Sender: TObject);//停止begin i:=j;end;
 
to de410:用您这个句子之后,则原来for i:=0 to sourcebmp.Height do 句则会[Error] Unit1.pas(44): For loop control variable must be simple local variable怎么办??
 
private { Private declarations } stop:boolean;procedure TForm1.BitBtn1Click(Sender: TObject);var i:integer; sourcebmp:Tbitmap; begin sourcebmp:=Tbitmap.Create; sourcebmp.LoadFromFile('e:/sunrise.bmp'); try for i:=0 to sourcebmp.Height do begin stretchblt(image1.Canvas.Handle ,0,0, image1.Width ,i, sourcebmp.Canvas.Handle,0,0, sourcebmp.Width,i,srccopy);// image1.Refresh ; sleep(3); if stop then break; Application.ProcessMessages; end; finally sourcebmp.Free ; end;end;procedure TForm1.stopClick(Sender: TObject);//停止begin stop:=true;end;
 
后退
顶部