**********如何中止线程********** 用线程连接数据库如果登陆失败则中止线程试了用Terminate发现没用线程继续执行用Free不知道可以吗问问大家不知道用什么方法好 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果只是想线程停下来, 用Suspend就可以了.想释放的话就用Free. Terminate将会中止线程运行. 最后会调用到free. 在线程的死循环里加上 if Terminated then exit; unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, ADODB;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; ADOQuery1: TADOQuery; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;type TMyThread = class(TThread) private protected procedure Execute;override;end;var Form1: TForm1; MyThread: TMyThread;implementation{$R *.dfm}procedure TMyThread.Execute;begin while true do begin beep(); sleep(100); if Terminated then exit; end;end;procedure TForm1.Button1Click(Sender: TObject);begin MyThread := TMyThread.Create(True); MyThread.Priority := tpLowest; MyThread.FreeOnTerminate := True; MyThread.Resume;end;procedure TForm1.Button2Click(Sender: TObject);begin MyThread.Terminate;end;end.如果没有我说的那句话,是不会停止的。 没错,或者这样写:procedure TMyThread.Execute;begin while not Terminated do begin beep(); sleep(100); end;end; 请问如何实现在程序上显示程序运行的时间,就是程序从启动到目前运行了多长时间,直到程序退出。 如何实现实现TELNET控制的屏幕显示? 请问怎么在脚本中使用varArrayCreate出来的自动化对象数组? 请问 我刚刚的帖子结贴的时候出问题了,请hch_45(HCH ~ahong.net~)和 nhdj(无名)两位进来接分 关于EXCEL,急,在线等! 帮我看看该怎么计算啊?在线等 待 如何在TOOLBUTTON上显示文字 对用户所选定的任意一页或者是任意几页进行打印 DELPHI打包的问题!会者不难! 如何获得图片(JPG文件)的真实尺寸? 关于TSecretPanel问题
if Terminated then exit;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TMyThread = class(TThread)
private protected
procedure Execute;override;
end;var
Form1: TForm1;
MyThread: TMyThread;implementation{$R *.dfm}
procedure TMyThread.Execute;
begin
while true do
begin
beep();
sleep(100);
if Terminated then exit;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
MyThread := TMyThread.Create(True);
MyThread.Priority := tpLowest;
MyThread.FreeOnTerminate := True;
MyThread.Resume;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
MyThread.Terminate;
end;end.如果没有我说的那句话,是不会停止的。
procedure TMyThread.Execute;
begin
while not Terminated do
begin
beep();
sleep(100);
end;
end;