delphi Createthread的线程传参数

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
Test=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调用处会报错。
implementation

uses 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;

 

posted @ 2013-06-13 14:39  Max Woods  阅读(1377)  评论(0编辑  收藏  举报