这个线程传递参数为什么不成功?(20分)

  • 主题发起人 主题发起人 kocus
  • 开始时间 开始时间
K

kocus

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
threadid:dword;
begin
CreateThread(nil,0,@tform1.threadfunc,label1,0,threadid);
end;

function tform1.ThreadFunc(var l:Tlabel):boolean;
begin
while strtoint(l.Caption)<10000do
l.Caption:=inttostr(strtoint(l.Caption)+1);
end;

运行后 他说非法访问0xfffffffff,说明label1没有传到l上
为什么会这样啊?
 
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
threadid:dword;
begin
CreateThread(nil,0,@tform1.threadfunc,Form1,0,threadid);
end;

function tform1.ThreadFunc(var l:TForm1):boolean;
begin
while strtoint(l.label1.Caption)<10000do
l.label1.Caption:=inttostr(strtoint(l.label1.Caption)+1);
end;

这样测试一下!
 
function ThreadFunc(l:Tlabel):boolean;stdcall;
begin
while strtoint(l.Caption)<10000do
l.Caption:=inttostr(strtoint(l.Caption)+1);
end;
 
function ThreadFunc(var l:TForm1):boolean;
begin
while strtoint(l.label1.Caption)<10000do
l.label1.Caption:=inttostr(strtoint(l.label1.Caption)+1);
end;

CreateThread(nil,0,threadfunc,Form1,0,threadid);
线程函数单独出来。
 
接受答案了.
 

Similar threads

M
回复
1
查看
271
zw84611
Z
回复
3
查看
351
迷惘的人
Q
回复
4
查看
356
穿越沦陷的爱
穿
后退
顶部