RSS订阅 | 匿名投稿
您的位置:网站首页 > 线程 > 正文

delphi TThread类的简单演示代码

作者:admin 来源:未知 日期:2010/5/9 14:55:24 人气: 标签:

代码如下:

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.


读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: