T
tl_lyq
Unregistered / Unconfirmed
GUEST, unregistred user!
unit KqtjUnt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, dxCntner, dxEditor, dxExEdtr,
dxEdLib, ExtCtrls, dxTL, dxDBCtrl, dxDBGrid, ComCtrls,DateUtils, Menus,
DBCtrls, dxDBTLCl, dxGrClms, Grids, DBGridEh, DBCtrlsEh, Mask, ToolWin,activex,
ImgList,ComObj;
type
TKqtj_frm = class(TForm)
ADOConnection1: TADOConnection;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
sb: TStatusBar;
ToolButton4: TToolButton;
Panel1: TPanel;
Label1: TLabel;
Label4: TLabel;
rq1: TDateTimePicker;
rq2: TDateTimePicker;
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TDatabaseThread = class(TThread)
private
FADOQuery:TADOQuery;
SQLString:string;
protected
procedure Execute;
override;
public
constructor Create(ADO:TADOQuery;S:String);
overload;
end;
var
Kqtj_frm: TKqtj_frm;
implementation
{$R *.dfm}
constructor TDatabaseThread.Create(ADO:TADOQuery;S:String);
begin
FADOQuery:=ADO;
SQLString:=S;
inherited Create(False);
end;
procedure TDatabaseThread.Execute;
begin
try
CoInitialize(nil);
fadoquery.Connection :=Kqtj_frm.ADOConnection1;
FreeOnTerminate:=True;
if FADOQuery <> nil then
begin
FADOQuery.Close;
fadoquery.CommandTimeout :=60000;
FADOQuery.SQL.Clear;
FADOQuery.SQL.Add(SQLString);
FADOQuery.ExecSQL;
end;
if Terminated then
//线程怎么好象处理不完了啊。一直等着也没有下边的提示。
begin
Kqtj_frm.sb.Panels[1].Text := '数据处理完成 ';
Kqtj_frm.sb.refresh;
exit;
end;
finally
CoUninitialize;
FreeAndNil(FADOQuery);
end;
end;
procedure TKqtj_frm.ToolButton2Click(Sender: TObject);
begin
self.close;
end;
procedure TKqtj_frm.ToolButton3Click(Sender: TObject);
var query:tadoquery;
begin
//开始线程处理
query:=tadoquery.Create(nil);
TDatabaseThread.Create(query, 'kqcalc ' ' '+datetostr(rq1.date)+ ' ' ', ' ' '+datetostr(rq2.date)+ ' ' ' ');
end;
end.
问题。1.线程结束后没有到上边的提示
2.如果用户强制结束线程如何写代码
没有用过线程,请大家指点一下。多谢。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, dxCntner, dxEditor, dxExEdtr,
dxEdLib, ExtCtrls, dxTL, dxDBCtrl, dxDBGrid, ComCtrls,DateUtils, Menus,
DBCtrls, dxDBTLCl, dxGrClms, Grids, DBGridEh, DBCtrlsEh, Mask, ToolWin,activex,
ImgList,ComObj;
type
TKqtj_frm = class(TForm)
ADOConnection1: TADOConnection;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
sb: TStatusBar;
ToolButton4: TToolButton;
Panel1: TPanel;
Label1: TLabel;
Label4: TLabel;
rq1: TDateTimePicker;
rq2: TDateTimePicker;
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TDatabaseThread = class(TThread)
private
FADOQuery:TADOQuery;
SQLString:string;
protected
procedure Execute;
override;
public
constructor Create(ADO:TADOQuery;S:String);
overload;
end;
var
Kqtj_frm: TKqtj_frm;
implementation
{$R *.dfm}
constructor TDatabaseThread.Create(ADO:TADOQuery;S:String);
begin
FADOQuery:=ADO;
SQLString:=S;
inherited Create(False);
end;
procedure TDatabaseThread.Execute;
begin
try
CoInitialize(nil);
fadoquery.Connection :=Kqtj_frm.ADOConnection1;
FreeOnTerminate:=True;
if FADOQuery <> nil then
begin
FADOQuery.Close;
fadoquery.CommandTimeout :=60000;
FADOQuery.SQL.Clear;
FADOQuery.SQL.Add(SQLString);
FADOQuery.ExecSQL;
end;
if Terminated then
//线程怎么好象处理不完了啊。一直等着也没有下边的提示。
begin
Kqtj_frm.sb.Panels[1].Text := '数据处理完成 ';
Kqtj_frm.sb.refresh;
exit;
end;
finally
CoUninitialize;
FreeAndNil(FADOQuery);
end;
end;
procedure TKqtj_frm.ToolButton2Click(Sender: TObject);
begin
self.close;
end;
procedure TKqtj_frm.ToolButton3Click(Sender: TObject);
var query:tadoquery;
begin
//开始线程处理
query:=tadoquery.Create(nil);
TDatabaseThread.Create(query, 'kqcalc ' ' '+datetostr(rq1.date)+ ' ' ', ' ' '+datetostr(rq2.date)+ ' ' ' ');
end;
end.
问题。1.线程结束后没有到上边的提示
2.如果用户强制结束线程如何写代码
没有用过线程,请大家指点一下。多谢。