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

来源:互联网 发布:mac有什么好玩的小游戏 编辑:程序博客网 时间:2024/04/25 18:49

转自:http://www.delphitop.com/html/xiancheng/1746.html

 

unit1

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;typeTest=record    a: Integer;    b: Integer;  end;  TForm1 = class(TForm)    btn1: TButton;    memo1: TMemo;    procedure btn1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  Form1: TForm1;    function MyThreadFun(var Param:  Test): Integer; stdcall; //注,此行写成TForm1.MyThreadFun Createthread调用处会报错。
implementationuses Unit2;{$R *.dfm}function MyThreadFun(var Param:  Test): Integer; stdcall;begin  Form1.Memo1.Text := IntToStr(Param.a);  Result := 0;end;procedure TForm1.btn1Click(Sender: TObject);var  Id: Dword;  P: test;begin  p.a:=5;  Createthread(nil, 0, @MyThreadFun, @p, 0, Id);end;


 

原创粉丝点击