我随便写的。你看看
unit uThread1;
interface
uses
Classes,SysUtils;
type
TRomInt = class(TThread)
private
{ Private declarations }
FSInt:integer;
FEint:integer;
FList:TStrings;
protected
procedure Execute;
override;
public
Constructor Create(Memo:TStrings;SInt,Eint:Integer);
end;
implementation
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TRomInt.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ TRomInt }
constructor TRomInt.Create(Memo:TStrings;SInt, Eint: Integer);
begin
FList:=Memo;
FSInt:=SInt;
FEint:=Eint;
inherited Create(True);
end;
procedure TRomInt.Execute;
var
i:integer;
begin
{ Place thread code here }
for i:=FSInt to FEintdo
begin
FList.Add(IntToStr(i));
if Terminated then
Exit;//停止将中断
end;
end;
end.
------调用--------
unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
BitBtn1: TBitBtn;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses uThread1;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
T1,T2,T3:TRomInt;
begin
with TRomInt.Create(Memo1.Lines,10000,19999)do
begin
Resume;
end;
with TRomInt.Create(Memo2.Lines,20000,29999)do
begin
Resume;
end;
with TRomInt.Create(Memo3.Lines,30000,39999)do
begin
Resume;
end;
end;