Hello
I need to have a threaded query which is used to populate a dbGrid.
On a form I put a TOracleSession, a TOracleDataSet a TDataSource and a TDbGrid.
These are passed to my TQueryThread object which runs the query and via a synchronized method links them all together and heypresto one populated DBGrid done via a thread.
The problem comes when I try to stop the query while it is running via a BreakExecution.
I run the program in delphi (I using the trial version to evulate the product)
First of all I get an error Ora-01013 which is fine then I get an application error Ora-01013 which is also as expected then the application shuts down which is not fine.
Could someboy please explain what I'm doing wrong ? I'm using Delphi 4 build 5.108 update pack 3, Windows NT service pack 6 and Oracle 7.3.4.
Many thanks
Paul
Here is the project code :
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Oracle, Db, OracleData, DBTables, Grids, DBGrids;
type
TQueryThread = class(TThread)
private
Session : TOracleSession;
Query : TOracleDataSet;
DataSource : TDataSource;
Grid : TDBGrid;
protected
procedure Execute; override;
procedure Start(aQuery : TOracleDataSet; aDS : TDataSource; aSession : TOracleSession; aGrid : TDBGrid);
procedure ConnectQuery;
end;
TForm1 = class(TForm)
OracleDataSet1: TOracleDataSet;
OracleSession1: TOracleSession;
grid: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure CREButton1Click(Sender: TObject);
procedure CREButton2Click(Sender: TObject);
procedure CREButton3Click(Sender: TObject);
procedure CREButton4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
QueryThread1 : TQueryThread;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.CREButton1Click(Sender: TObject);
begin
Oraclesession1.connected := True;
end;
procedure TForm1.CREButton2Click(Sender: TObject);
var i : integer;
begin
QueryThread1 := TQueryThread.Create(True);
QueryThread1.Start(OracleDataSet1,DataSource1,OracleSession1,Grid);
end;
procedure TQueryThread.Execute;
begin
Query.Open;
Synchronize(ConnectQuery);
end;
procedure TQueryThread.Start(aQuery : TOracleDataSet; aDS : TDataSource; aSession : TOracleSession; aGrid : TDBGrid);
begin
FreeOnTerminate := True;
Query := aQuery;
DataSource := aDS;
Session := aSession;
Query.Session := Session;
Grid := aGrid;
Resume;
end;
procedure TQueryThread.ConnectQuery;
begin
Grid.DataSource := DataSource;
DataSource.DataSet := Query;
end;
procedure TForm1.CREButton3Click(Sender: TObject);
begin
OracleDataSet1.Close;
end;
procedure TForm1.CREButton4Click(Sender: TObject);
begin
OracleSession1.BreakExecution;
end;
end.
I need to have a threaded query which is used to populate a dbGrid.
On a form I put a TOracleSession, a TOracleDataSet a TDataSource and a TDbGrid.
These are passed to my TQueryThread object which runs the query and via a synchronized method links them all together and heypresto one populated DBGrid done via a thread.
The problem comes when I try to stop the query while it is running via a BreakExecution.
I run the program in delphi (I using the trial version to evulate the product)
First of all I get an error Ora-01013 which is fine then I get an application error Ora-01013 which is also as expected then the application shuts down which is not fine.
Could someboy please explain what I'm doing wrong ? I'm using Delphi 4 build 5.108 update pack 3, Windows NT service pack 6 and Oracle 7.3.4.
Many thanks
Paul
Here is the project code :
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Oracle, Db, OracleData, DBTables, Grids, DBGrids;
type
TQueryThread = class(TThread)
private
Session : TOracleSession;
Query : TOracleDataSet;
DataSource : TDataSource;
Grid : TDBGrid;
protected
procedure Execute; override;
procedure Start(aQuery : TOracleDataSet; aDS : TDataSource; aSession : TOracleSession; aGrid : TDBGrid);
procedure ConnectQuery;
end;
TForm1 = class(TForm)
OracleDataSet1: TOracleDataSet;
OracleSession1: TOracleSession;
grid: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure CREButton1Click(Sender: TObject);
procedure CREButton2Click(Sender: TObject);
procedure CREButton3Click(Sender: TObject);
procedure CREButton4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
QueryThread1 : TQueryThread;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.CREButton1Click(Sender: TObject);
begin
Oraclesession1.connected := True;
end;
procedure TForm1.CREButton2Click(Sender: TObject);
var i : integer;
begin
QueryThread1 := TQueryThread.Create(True);
QueryThread1.Start(OracleDataSet1,DataSource1,OracleSession1,Grid);
end;
procedure TQueryThread.Execute;
begin
Query.Open;
Synchronize(ConnectQuery);
end;
procedure TQueryThread.Start(aQuery : TOracleDataSet; aDS : TDataSource; aSession : TOracleSession; aGrid : TDBGrid);
begin
FreeOnTerminate := True;
Query := aQuery;
DataSource := aDS;
Session := aSession;
Query.Session := Session;
Grid := aGrid;
Resume;
end;
procedure TQueryThread.ConnectQuery;
begin
Grid.DataSource := DataSource;
DataSource.DataSet := Query;
end;
procedure TForm1.CREButton3Click(Sender: TObject);
begin
OracleDataSet1.Close;
end;
procedure TForm1.CREButton4Click(Sender: TObject);
begin
OracleSession1.BreakExecution;
end;
end.