unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
DB, ADODB,
ActiveX;
type
TCheckThread=Class(TThread)
private
FConn:TAdoconnection;
FErr:Boolean;
protected
Procedure Execute;
override;
Destructor Destroy;
override;
public
Property Error:Boolean
read FErr;
Constructor Create(Acon:TAdoConnection);
End;
TForm5 =
class(TForm)
ADOConnection1: TADOConnection;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure MyOnTermiante(Sender: TObject);
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form5: TForm5;
implementation
uses JRO_TLB,ADODB_TLB;
{$R *.dfm}
procedure TForm5.MyOnTermiante(Sender: TObject);
begin
if TCheckThread(Sender).Error
then Showmessage('
Fehler')
else Showmessage('
OK')
end;
procedure TForm5.Button1Click(Sender: TObject);
begin
With TCheckThread.create(AdoConnection1)
do OnTerminate := MyOnTermiante;
end;
{ TCheckThread }
constructor TCheckThread.Create(Acon: TAdoConnection);
begin
inherited Create(false);
CoInitialize(
nil);
FConn := Acon;
FreeOnTerminate := true;
end;
destructor TCheckThread.Destroy;
begin
CoUninitialize;
inherited;
end;
procedure TCheckThread.Execute;
begin
inherited;
With TAdoConnection.Create(
nil)
do
try
ConnectionString:= Fconn.ConnectionString;
try
ConnectionTimeOut := 2;
CommandTimeOut := 2;
connected := true;
except
FErr := true;
end;
finally
Free;
end;
end;
end.