var threadid1:DWord; begin CreateThread(nil,0,@TForm1.OutText1,nil,0,threadid1); if threadid1.Waitfor then begin showmessage('bb'); end; end; 为什么这样写在编译时出错,出错在第二行, record,object or class type required
为什么不用线程类 YourThread:=TYourThread.Create(False); YourThread.OnTerminate:=isComplete;//指定线程结束的事件方法 .... procedure TForm1.iscomplete(sender:Tobject); begin .......... end;
看你的问题似乎可以这样: 你new一个工程,放两个button,一个是start,一个是stop,一个edit,利用循环来检测edit内容,检测的同时你可以对edit进行编辑procedure TForm1.Button1Click(Sender: TObject); begin while true do begin application.ProcessMessages; if button2.Tag=99 then exit; if edit1.Text='' then edit1.Text:='aaa'; end; end;procedure TForm1.Button2Click(Sender: TObject); begin button2.Tag:=99; end;
var threadid1:DWord; begin CreateThread(nil,0,@TForm1.OutText1,nil,0,threadid1); if threadid1.Waitfor then begin showmessage('bb'); end; end; 为什么这样写在编译时出错,出错在第二行, record,object or class type required ----threadid1 為線程id 非線程對象 --你可新建議個線程對象 將你的操作放在Execute中 就可用 YouThread.Waitfor 等待 線程YouThread 結束
begin
......
end;
threadid1:DWord;
begin
CreateThread(nil,0,@TForm1.OutText1,nil,0,threadid1);
if threadid1.Waitfor then
begin
showmessage('bb');
end;
end;
为什么这样写在编译时出错,出错在第二行,
record,object or class type required
YourThread:=TYourThread.Create(False);
YourThread.OnTerminate:=isComplete;//指定线程结束的事件方法
....
procedure TForm1.iscomplete(sender:Tobject);
begin
..........
end;
可能这是一个比较基础的方法,我现在在做C的程序的时候就是用的这种方法,可能在delphi中有更好的处理方法,关注。
可否讲得具体些!
你new一个工程,放两个button,一个是start,一个是stop,一个edit,利用循环来检测edit内容,检测的同时你可以对edit进行编辑procedure TForm1.Button1Click(Sender: TObject);
begin
while true do
begin
application.ProcessMessages;
if button2.Tag=99 then exit;
if edit1.Text='' then
edit1.Text:='aaa';
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
button2.Tag:=99;
end;
你的方法是可以,但是CPU使用率100%啊,程序效率不高啊!
threadid1:DWord;
begin
CreateThread(nil,0,@TForm1.OutText1,nil,0,threadid1);
if threadid1.Waitfor then
begin
showmessage('bb');
end;
end;
为什么这样写在编译时出错,出错在第二行,
record,object or class type required
----threadid1 為線程id 非線程對象
--你可新建議個線程對象
將你的操作放在Execute中
就可用
YouThread.Waitfor
等待 線程YouThread 結束
用GetExitCodeThread也可以判断出她是否已经结束