delphi中,我用定时器每隔一段时间执行数据库插入及更新工作!
adoquery.close;
adoquery.sql.cleare;
adoquery.connection:=con1;
adoquery.sql.add('exec addery');
execsql;
上面的基本语句!
我的问题是:定时器执行时,在软件界面就会很卡,无法操作!请问是不是需要创建一个线程才能处理卡的问题呢?请大神们帮帮忙!非常感谢!如果是需要写线程,更希望能把线程也写出来!非常感谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
ADOConnection1: TADOConnection;
procedure BitBtn1Click(Sender: TObject);
private
public
end;
Type
TAdoExec = Class(TThread)
Private
Public
Protected
Procedure Execute; Override;
End;
var
Form1: TForm1;
implementation
uses ActiveX;
{$R *.dfm}
{ TAdoExec }
procedure TAdoExec.Execute;
begin
Inherited;
ActiveX.CoInitialize(Nil);
Try
With TADOQuery.Create(Nil) Do
Begin
ConnectionString :=
'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TEST;Data Source=.';
SQL.Add('Select * From Tree');
ExecSQL;
Free;
End;
Finally
ActiveX.CoUninitialize;
Terminate;
End;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
TAdoExec.Create(False);
end;
end.