我初学线程,根据网上的资料学到了用下面的语句来建立线程,问题是我怎么在不退出程序的情况下 ,结束或暂停这个线程。找过答案,好多都是jave或c的,没有delphi的,哪位大哥指点指点哈
function MyThreadFunc(P:pointer):Longint;stdcall;
var
i:longint;
DC:HDC;
S:string;
begin
DC:=GetDC(Form1.Handle);
for i:=0 to 500000 do begin
S:=Inttostr(i);
Textout(DC,10,10,Pchar(S),length(S));
end;
ReleaseDC(Form1.Handle,DC);
end;
procedure TForm1.UsedThreadClick(Sender: TObject);
var
hThread:Thandle;//定义一个句柄
ThreadID:DWord;
begin
//创建线程,同时线程函数被调用
hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);
if hThread=0 then
messagebox(Handle,'Didn’tCreateaThread',nil,MB_OK);
end;
function MyThreadFunc(P:pointer):Longint;stdcall;
var
i:longint;
DC:HDC;
S:string;
begin
DC:=GetDC(Form1.Handle);
for i:=0 to 500000 do begin
S:=Inttostr(i);
Textout(DC,10,10,Pchar(S),length(S));
end;
ReleaseDC(Form1.Handle,DC);
end;
procedure TForm1.UsedThreadClick(Sender: TObject);
var
hThread:Thandle;//定义一个句柄
ThreadID:DWord;
begin
//创建线程,同时线程函数被调用
hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);
if hThread=0 then
messagebox(Handle,'Didn’tCreateaThread',nil,MB_OK);
end;
解决方案 »
- 高分求救,动态生成多个DbEditEh后,如何在DbEditEhButton的Click事件中判断,是哪个DBEdithEh的Button产生的事件
- dxDBGrid列求和怎么没有效果啊??
- 着急中!!!请问在局域网里,怎么查对方的IP?
- 如何用Filter方法取得某一天的记录?
- 清空数据库表格时,用EMPTYTABLE;语句时,发生 'table is busy.'这样的错误,是什么引起的?
- 我的ICON怎么不能加载到任务栏中的状态栏呢?(附代码)
- 请教delphi的配置问题?
- 请问那里有Delphi的反编译软件!
- 关于webbrowser的问题?
- 请问如何在线程中创建DATAMODUAL的实例啊?
- 请求高人 谁有delphi7类结构图和好的delphi参考手册。
- 急!帮看一个错误!!!!!!!!!!!!!!!!!!!!!!!!!!!
thread: TSendThread;
begin
thread := TSendThread.Create(False);
thread.FreeOnTerminate := True;
// 中止
thread.Terminate;
end;
thread: TSendThread;
运行的时候说没有定义哈”TSendThread“
还有就是这个是终止全部线程吗,还是就终止一个?
thread: TThread;
begin
thread := TThread.Create(False);
thread.FreeOnTerminate := True;
// 中止
thread.Terminate;
end;