淡
淡淡的笑
Unregistered / Unconfirmed
GUEST, unregistred user!
新建项目,在窗口上放一个memo和一个按钮
代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Winsock, Grids, ExtCtrls, Menus, ComCtrls;
type
TForm1 = class(TForm)
button1: TButton;
Memo1: TMemo;
procedure button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread = class(TThread)
private
{ Private declarations }
indexNum:integer;
procedure AddThread;
procedure ProgressMy(iNum:integer);
protected
procedure Execute;
override;
public
constructor Create(iNum:integer);
end;
var
Form1: TForm1;
MaxNum:integer;
ThreadNum:integer;
implementation
{$R *.DFM}
procedure TForm1.button1Click(Sender: TObject);
var
PingResult:string;
MyAddr:string;
x,y:integer;
i,j,k:integer;
begin
ThreadNum:=10;
MaxNum:=34;
// <<<=== 这个设大一点,程序便出错,请问程序要怎么改或怎么改比较好?
if MaxNum>ThreadNum then
j:=ThreadNum
else
j:=MaxNum;
for i := 1 to jdo
begin
k:=i-1;
TMyThread.Create(k);
end;
end;
{ TMyThread }
procedure TMyThread.AddThread;
var
i:integer;
begin
//重用线程,结果处理结束后就处理新的任务
i:=indexNum+ThreadNum;
if i<=MaxNum then
begin
ProgressMy(i);
end;
end;
constructor TMyThread.Create(iNum: integer);
begin
indexNum:=iNum;
inherited Create(False);
end;
procedure TMyThread.Execute;
begin
//inherited;
FreeOnTerminate := True;
ProgressMy(indexNum);
end;
procedure TMyThread.ProgressMy(iNum:integer);
var
i:integer;
begin
i:=iNum;
indexNum:=i;
form1.memo1.text:= form1.memo1.text + '|' + inttostr(i);
AddThread;
end;
end.