delphi Createthread的线程传参数(小熊论坛的)

示例一:

Test=record

    a: Integer;

    b: Integer;

  end;

  

  function MyThreadFun(var Param:  Test): Integer; stdcall;

begin

  Form1.Memo1.Text := IntToStr(Param.a);    

  Result := 0;

end;



procedure TForm1.Button3Click(Sender: TObject);

var

  Id: Dword;

  P: test;

begin

  p.a:=5;

  Createthread(nil, 0, @MyThreadFun, @p, 0, Id);

end;
View Code

 

示例二:

  PTest = ^Test;

  Test=record

    a: Integer;

    b: Integer;

  end;

  

  function MyThreadFun(Param: Pointer): Integer; stdcall;

begin

  Form1.Memo1.Text := IntToStr(PTest(Param)^.a);

  Result := 0;

end; 



procedure TForm1.Button3Click(Sender: TObject);

var

  Id: Dword;

  P: test;

begin

  p.a:=5;

  Createthread(nil, 0, @MyThreadFun, @p, 0, Id);

end;
View Code

 

你可能感兴趣的:(thread)