unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IBConnectionBroker, ExtCtrls, StdCtrls;

const
  MaxConn = 30;

type
  TForm1 = class(TForm)
    IBConnectionBroker1: TIBConnectionBroker;
    Available: TLabel;
    Allocated: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Timer1: TTimer;
    Button1: TButton;
    Button2: TButton;
    Memo1: TMemo;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure IBConnectionBroker1Log(Sender: TObject; LogMessage: String);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Threads : Array[1..MaxConn] of TThread;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  // Show the current load.

  Edit1.Text := IntToStr(IBConnectionBroker1.AvailableConnections);
  Edit2.Text := IntToStr(IBConnectionBroker1.AllocatedConnections);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
begin
  // Create the threads

  for i := 1 to MaxConn do
  begin
    Threads[i] := TTestthread.Create(false);
    Threads[i].FreeOnTerminate := true;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  i : Integer;
begin
  //  Terminate the threads

  for i := 1 to MaxConn do
  begin
    Threads[i].Terminate;
    Threads[i] := nil;
  end;
end;

procedure TForm1.IBConnectionBroker1Log(Sender: TObject;
  LogMessage: String);
begin
  Memo1.Lines.Add(LogMessage);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Timer1.Enabled := false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // This starts up the pooler and "primes" the pump to the MinConenctions level
  // That is the initial delay you are seeing at startup.

  IBConnectionBroker1.Init;
end;

end.
