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;
原文地址:https://www.cnblogs.com/MaxWoods/p/3133998.html