网
网事如风
Unregistered / Unconfirmed
GUEST, unregistred user!
//多线程类申明!
TAdoSD_Thread = class(TThread)
private
FSQLString : string;
FADOQuery : TADOQuery;
FStringGrd : TbsskinStringGrid;
FLabel : TLabel;
protected
procedure Execute;
override;
public
constructor Create(ADO:TADOQuery;
SGRD:TbsskinStringGrid;
S: String;Lab: TLabel);
overload;
procedure SQLtoStringGrid;
end;
//线程类TAdoSD_Thread的实现:
constructor TAdoSD_Thread.Create(ADO: TADOQuery;
SGrd:TbsskinStringGrid;
S: String;Lab: TLabel);
begin
FADOQuery := ADO;
FStringGrd := SGrd ;
FSQLString := S;
FLabel := Lab;
inherited Create(False);
end;
procedure TAdoSD_Thread.Execute;
begin
FreeOnTerminate:=True;
Synchronize(SQLtoStringGrid);
if Terminated then
exit;
end;
procedure TAdoSD_Thread.SQLtoStringGrid;
var
i,j : integer;
begin
if FADOQuery<>nil then
begin
FADOQuery.Close;
FADOQuery.SQL.Text := FSQLString;
FADOQuery.Open;
end;
if FADOQuery.RecordCount < 1 then
Exit;
NowRowCou := FStringGrd.RowCount - 1;
FStringGrd.RowCount := NowRowCou + FADOQuery.RecordCount + 1;
if FADOQuery.Eof = false then
begin
for i := 1 to FADOQuery.RecordCountdo
begin
FStringGrd.Cells[ 0,NowRowCou + i] := inttostr(NowRowCou + i);
for j := 1 to 18 do
FStringGrd.Cells[ j,NowRowCou + i] :=
FADOQuery.Fields.Field[j-1].AsString;
FADOQuery.Next;
end;
end
else
FADOQuery.Close;
end;
//多线程类的调用:
调用时的语句如下:
AdoSD_Thread := TAdoSD_Thread.Create(DM.ADOQry_CX, SBcx_Grd,string_sql,Label1);
AdoSD_Thread.Execute;
那么会执行两次SQLtoStringGrid中代码,如果注释掉AdoSD_Thread.Execute;则是所要结果。
AdoSD_Thread := TAdoSD_Thread.Create(DM.ADOQry_CX,SBcx_Grd,string_sql,Label1);
什么都没做啊!
可事实是它执行了SQLtoStringGrid中的代码,高手给解释下,谢谢!
TAdoSD_Thread = class(TThread)
private
FSQLString : string;
FADOQuery : TADOQuery;
FStringGrd : TbsskinStringGrid;
FLabel : TLabel;
protected
procedure Execute;
override;
public
constructor Create(ADO:TADOQuery;
SGRD:TbsskinStringGrid;
S: String;Lab: TLabel);
overload;
procedure SQLtoStringGrid;
end;
//线程类TAdoSD_Thread的实现:
constructor TAdoSD_Thread.Create(ADO: TADOQuery;
SGrd:TbsskinStringGrid;
S: String;Lab: TLabel);
begin
FADOQuery := ADO;
FStringGrd := SGrd ;
FSQLString := S;
FLabel := Lab;
inherited Create(False);
end;
procedure TAdoSD_Thread.Execute;
begin
FreeOnTerminate:=True;
Synchronize(SQLtoStringGrid);
if Terminated then
exit;
end;
procedure TAdoSD_Thread.SQLtoStringGrid;
var
i,j : integer;
begin
if FADOQuery<>nil then
begin
FADOQuery.Close;
FADOQuery.SQL.Text := FSQLString;
FADOQuery.Open;
end;
if FADOQuery.RecordCount < 1 then
Exit;
NowRowCou := FStringGrd.RowCount - 1;
FStringGrd.RowCount := NowRowCou + FADOQuery.RecordCount + 1;
if FADOQuery.Eof = false then
begin
for i := 1 to FADOQuery.RecordCountdo
begin
FStringGrd.Cells[ 0,NowRowCou + i] := inttostr(NowRowCou + i);
for j := 1 to 18 do
FStringGrd.Cells[ j,NowRowCou + i] :=
FADOQuery.Fields.Field[j-1].AsString;
FADOQuery.Next;
end;
end
else
FADOQuery.Close;
end;
//多线程类的调用:
调用时的语句如下:
AdoSD_Thread := TAdoSD_Thread.Create(DM.ADOQry_CX, SBcx_Grd,string_sql,Label1);
AdoSD_Thread.Execute;
那么会执行两次SQLtoStringGrid中代码,如果注释掉AdoSD_Thread.Execute;则是所要结果。
AdoSD_Thread := TAdoSD_Thread.Create(DM.ADOQry_CX,SBcx_Grd,string_sql,Label1);
什么都没做啊!
可事实是它执行了SQLtoStringGrid中的代码,高手给解释下,谢谢!