一个多县城提取数据库数据的列子
unit Unit2;
interface
uses
Classes,ADODB,SysUtils,ActiveX;
type
Ta = class(TThread)
constructor Create(ado:Tadoquery;s:string);
destructor Destroy;override;
private
a:Tadoquery;
ss:string;
{ Private declarations }
protected
procedure Execute;
override;
end;
implementation
uses unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Ta.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ Ta }
constructor Ta.Create(ado:Tadoquery;s:string);
begin
inherited create(true);
FreeOnTerminate:=true;
a:=ado;
ss:=s;
Resume;
end;
procedure Ta.Execute;
begin
CoInitialize(nil);//必须的
sleep(5000);
a.SQL.Add(ss);
try
a.Open;
except
raise
end;
end;
destructor Ta.Destroy;
begin
a:=nil;
inherited Destroy;
end;
主窗体的调用
var t:Ta;
begin
t:=Ta.Create(adoquery1,'select * from 成绩');