B
blkfires
Unregistered / Unconfirmed
GUEST, unregistred user!
nit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,forms,
StdCtrls, DB, Grids, DBGrids, ADODB;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
dbthread = class(TThread)
private
protected
mquery:Tadoquery;
mconnection:Tadoconnection;
mdatasource:Tdatasource;
procedure Execute;
override;
procedure createconnection;
procedure hook;
public
constructor create(q:Tadoquery;conn:Tadoconnection;data:Tdatasource);virtual;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor dbthread.create(q:Tadoquery;conn:Tadoconnection;data:Tdatasource);
begin
inherited create(true);
mquery:=q;
mconnection:=conn;
mdatasource:=data;
freeonterminate:=true;
resume;
end;
procedure dbthread.Execute;
begin
createconnection;
mquery.Open;
synchronize(hook);
end;
procedure dbthread.createconnection;
var
str:string;
begin
str:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fang;Data Source=FANG-A436922EE0';
mconnection.ConnectionString:=str;
mquery.Connection:=mconnection;
mquery.Sql.Clear;
mquery.SQL.Add('select * from t1');
end;
procedure dbthread.hook;
begin
mdatasource.DataSet:=mquery;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
dbthread.create(adoquery1,adoconnection1,datasource1);
end;
end.
可以运行,却没反映,不知道问题在哪,我是新手,大家帮忙。
另外象TADOQUERY这些组件是不是只能在有界面的单元里编辑啊,好象在新开的线程单元里不能编辑。
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,forms,
StdCtrls, DB, Grids, DBGrids, ADODB;
type
TForm1 = class(TForm)
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
dbthread = class(TThread)
private
protected
mquery:Tadoquery;
mconnection:Tadoconnection;
mdatasource:Tdatasource;
procedure Execute;
override;
procedure createconnection;
procedure hook;
public
constructor create(q:Tadoquery;conn:Tadoconnection;data:Tdatasource);virtual;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor dbthread.create(q:Tadoquery;conn:Tadoconnection;data:Tdatasource);
begin
inherited create(true);
mquery:=q;
mconnection:=conn;
mdatasource:=data;
freeonterminate:=true;
resume;
end;
procedure dbthread.Execute;
begin
createconnection;
mquery.Open;
synchronize(hook);
end;
procedure dbthread.createconnection;
var
str:string;
begin
str:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=fang;Data Source=FANG-A436922EE0';
mconnection.ConnectionString:=str;
mquery.Connection:=mconnection;
mquery.Sql.Clear;
mquery.SQL.Add('select * from t1');
end;
procedure dbthread.hook;
begin
mdatasource.DataSet:=mquery;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
dbthread.create(adoquery1,adoconnection1,datasource1);
end;
end.
可以运行,却没反映,不知道问题在哪,我是新手,大家帮忙。
另外象TADOQUERY这些组件是不是只能在有界面的单元里编辑啊,好象在新开的线程单元里不能编辑。