高手帮忙,多线程下载数据却无法更新.
mator 2004-09-30 01:41:55 TGetDBThread = class(TThread)
private
{ Private declarations }
Fqry:TAdoquery;
Fsource:Tdatasource;
Fexception:Exception;
procedure HookUI;
procedure qryerror;
procedure timestart;
protected
procedure Execute; override;
public
constructor Create(Q:Tadoquery;S:Tdatasource);virtual;
end;
constructor TGetDBThread.Create(Q: Tadoquery; S: Tdatasource);
begin
inherited Create(true);
Fqry:=q;
Fsource:=s;
FreeOnTerminate:=true;
Resume;
end;
procedure TGetDBThread.Execute;
begin
if Terminated then exit;
try
Fqry.Open;
if Fqry.Locate('a',0,[])=false then Fqry.First;
Synchronize(HookUI);
Synchronize(Timestart);
except
Fexception:=ExceptObject as Exception;
Synchronize(qryerror);
end;
end;
procedure TGetDBThread.HookUI;
begin
Fsource.DataSet:=Fqry;
end;
procedure TGetDBThread.qryerror;
begin
Application.ShowException(fexception);
end;
procedure TGetDBThread.timestart;
begin
mgcfrm.Timer1.Enabled:=true;
end;
以上是线程中接收数据的代码,下面是进入线程前的代码
procedure Tmgcfrm.loadrecord(dtbegin:Tdatetime;value,Recono:string);
var
newThread:Tgetdbthread;
begin
with qrysql do
begin
close;
sql.Clear;
sql.Add('select * from table');
end;
newthread:=Tgetdbthread.Create(qrysql,datasource1);
end;
第一次接收到数据在DBGRID里是正常的,以后就无法更新了
我是用TIMER控件没N秒接收一次的,请高手帮忙,感激不尽