主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:150次

代码如下:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    start: TButton;
    Memo1: TMemo;
    procedure startClick(Sender: TObject);
  *******
    { Private declarations }
  public
    { Public declarations }
  end;

  TMyThread = class(TThread)
  *******
      FMyThreadID:integer;
  public
      constructor Create(CreateSuspended:Boolean;MyThreadID:integer);overload;
      procedure execute;override;
  end;


var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.startClick(Sender: TObject);
var
  i: integer;
  TestThread: TMyThread;
begin
for i:=0 to 9 do
  begin
    TestThread:=TMyThread.Create(false,i+1);
  end;

end;


constructor TMyThread.Create(CreateSuspended:Boolean;MyThreadID:integer);
  begin
      inherited  Create(CreateSuspended);
      FMyThreadID:=MyThreadID;
  end;

  procedure TMyThread.execute;
  begin
      //Showmessage('线程'+IntToStr(FMyThreadID));
      form1.Memo1.Text:= '线程'+IntToStr(FMyThreadID);
  end;


end.


关键字词: