unit ConnectionPoolingMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uDADriverManager, uDAClasses, StdCtrls, uDAInterfaces, uDAIBXDriver, uDAEngine, uDAADODriver, ExtCtrls, ComCtrls; type TConnectionPoolingMainForm = class(TForm) DADriverManager: TDADriverManager; DAConnectionManager: TDAConnectionManager; Acquire1Button: TButton; cbConnections: TComboBox; DAADODriver: TDAADODriver; Release1Button: TButton; Memo: TMemo; Acquire2Button: TButton; Release2Button: TButton; Acquire3Button: TButton; Release3Button: TButton; Label1: TLabel; TrackBar: TTrackBar; lPoolTimeoutSeconds: TLabel; procedure FormCreate(Sender: TObject); procedure Acquire1ButtonClick(Sender: TObject); procedure Release1ButtonClick(Sender: TObject); procedure Acquire2ButtonClick(Sender: TObject); procedure Acquire3ButtonClick(Sender: TObject); procedure Release2ButtonClick(Sender: TObject); procedure Release3ButtonClick(Sender: TObject); procedure DAConnectionManagerConnectionAcquired( Sender: TDAConnectionManager; const Connection: IDAConnection); procedure DAConnectionManagerConnectionCreated( Sender: TDAConnectionManager; const Connection: IDAConnection); procedure DAConnectionManagerConnectionTimedOut( Sender: TDAConnectionManager); procedure TrackBarChange(Sender: TObject); procedure FormDestroy(Sender: TObject); private fConnection, fConnection2, fConnection3: IDAConnection; procedure Log(Str: string); public end; var ConnectionPoolingMainForm: TConnectionPoolingMainForm; implementation {$R *.dfm} procedure TConnectionPoolingMainForm.FormCreate(Sender: TObject); var i: integer; begin for i := 0 to (DAConnectionManager.Connections.Count - 1) do cbConnections.Items.Add(DAConnectionManager.Connections[i].Name); cbConnections.ItemIndex := 0; end; procedure TConnectionPoolingMainForm.Acquire1ButtonClick(Sender: TObject); begin if not assigned(fConnection) then begin fConnection := DAConnectionManager.NewConnection(cbConnections.Text); Log('Connection #1 acquired...'); end; end; procedure TConnectionPoolingMainForm.Release1ButtonClick(Sender: TObject); begin if assigned(fConnection) then begin fConnection := nil; Log('Connection #1 released'); end; end; procedure TConnectionPoolingMainForm.Acquire2ButtonClick(Sender: TObject); begin if not assigned(fConnection2) then begin fConnection2 := DAConnectionManager.NewConnection(cbConnections.Text); Log('Connection #2 acquired...'); end; end; procedure TConnectionPoolingMainForm.Acquire3ButtonClick(Sender: TObject); begin if not assigned(fConnection3) then begin fConnection3 := DAConnectionManager.NewConnection(cbConnections.Text); Log('Connection #3 acquired...'); end; end; procedure TConnectionPoolingMainForm.Release2ButtonClick(Sender: TObject); begin if assigned(fConnection2) then begin fConnection2 := nil; Log('Connection #2 released'); end; end; procedure TConnectionPoolingMainForm.Release3ButtonClick(Sender: TObject); begin if assigned(fConnection3) then begin fConnection3 := nil; Log('Connection #3 released'); end; end; procedure TConnectionPoolingMainForm.DAConnectionManagerConnectionAcquired( Sender: TDAConnectionManager; const Connection: IDAConnection); begin Log('EVENT -> Connection acquired from the pool at ' + TimeToStr(Now)); end; procedure TConnectionPoolingMainForm.DAConnectionManagerConnectionCreated( Sender: TDAConnectionManager; const Connection: IDAConnection); begin Log('EVENT -> New connection created at ' + TimeToStr(Now)); end; procedure TConnectionPoolingMainForm.DAConnectionManagerConnectionTimedOut( Sender: TDAConnectionManager); begin Log('EVENT -> A connection timed out at ' + TimeToStr(Now)); end; procedure TConnectionPoolingMainForm.TrackBarChange(Sender: TObject); begin DAConnectionManager.PoolTimeoutSeconds := TrackBar.Position; lPoolTimeoutSeconds.Caption := Format('PoolTimeoutSeconds: %d', [TrackBar.Position]); end; procedure TConnectionPoolingMainForm.Log(Str: string); begin Memo.Lines.Add(Str); end; procedure TConnectionPoolingMainForm.FormDestroy(Sender: TObject); begin fConnection:=nil; fConnection2:=nil; fConnection3:=nil; end; end.