delphi TThread类的简单演示代码


代码如下:

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.


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678