在窗体上添加一个变量,在线程创建和释放的事件中,分别对该变量加减1,即可!
type
TForm1 = class(TForm)
private
FThreadCount: Integer;
procedure SetThreadCount(const Value: Integer);
{ Private declarations }
public
{ Public declarations }
property ThreadCount : Integer read FThreadCount write SetThreadCount;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.SetThreadCount(const Value: Integer);
begin
if FThreadCount = Value then
Exit;
FThreadCount := Value;
if FThreadCount < 5 then
begin
with TThread.Create(False)do
begin
..............
end;
end;
end;