I just can not get it to work because it gives me the error "invalid database handle (no active connection)"
But my code is right I do not understand why this error.
Code: Select all
type
TQueryThread = class(TThread)
private
FConnection: TIBCConnection;
FTransaction : TIBCTransaction;
FQuery: TLFQuery;
public
procedure Execute ; override;
function CancelOpening : Boolean;
constructor Create;
destructor Destroy; Override;
end;
var
Form1: TForm1;
QueryThread: TQueryThread;
implementation
{$R *.dfm}
constructor TQueryThread.Create;
begin
inherited Create(False);
FreeOnTerminate := True;
FConnection := TIBCConnection.Create(Nil);
FConnection.Database := 'D:\Banco de Dados\Casual\Banco Antigo\DATA-EXPERT.DAE';
FConnection.Username := 'SYSDBA';
FConnection.Password := 'masterkey';
FConnection.Connected := True;
FTransaction := TIBCTransaction.Create(Nil);
FTransaction.DefaultConnection := FConnection;
FTransaction.Active := True;
FQuery := TLFQuery.Create(nil);
FQuery.Connection := FConnection;
FQuery.Transaction := FTransaction;
FQuery.SQL.Text := Form1.Memo1.Text;
end;
destructor TQueryThread.Destroy;
begin
FQuery.Free;
FConnection.Free;
inherited;
end;
function TQueryThread.CancelOpening : boolean;
begin
Result := not FQuery.Fetched;
if Result then FQuery.BreakExec; // Error invalid database handle (no active connection)
end;
procedure TQueryThread.Execute;
begin
inherited;
FQuery.Open;
end;
procedure TForm1.Btn_OpenClick(Sender: TObject);
begin
QueryThread := TQueryThread.Create;
end;
procedure TForm1.Btn_CancelClick(Sender: TObject);
begin
if QueryThread.CancelOpening then
Showmessage('Cancelou')
Else
Showmessage('Executando');
end;
I have not put the database to be very large however you can use any database of yours that has a large table.
https://mega.nz/#!JmZ1lQKA!QhA3vVVyPWiK ... 3vuZ__oam8