我的情况是这样的,程序是三层结构,系统查询提交给服务器中间件查询,但是返回的时间很慢,请问用什么方法可以解决,如果开一个线程的要怎么用,因为我这个窗体是继承下来的.
procedure TfrwBillQuery.SumOfOrgan(Sender: TObject);
var
cStartDate: String;
cEndDate: String;
oSumList: Variant;
oSumTotal: Variant;
oSumSales: Variant;
oSumOrgan: Variant;
cPath: String;
cParentPath: String;
cPointNo: String;
cPointName: String;
oNode: TTreenode;
pNode: ^String;
nLen: Integer;
nLevel: Integer;
i: Integer;
begin
cStartDate := DateToStr(Self.dtpStart.Date);
cEndDate := DateToStr(Self.dtpEnd.Date);
gcPointNo := ''; oNode := Self.tvOrgan.Selected;
Self.lblUnitName4.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName3.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName2.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName1.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName.Caption := '统计单位: '+oNode.Text; pNode := oNode.Data;
nLevel := oNode.Level + 1;
cParentPath := pNode^;
nLen := Length(cParentPath); Self.tbGroups.Close;
Self.tbGroups.CreateDataSet; for i := 0 to Self.tvOrgan.Items.Count - 1 do
begin
oNode := Self.tvOrgan.Items.Item[i];
cPointNo := oNode.Text;
cPointName := Copy(cPointNo,6,Length(cPointNo)-5);
cPointNo := Copy(cPointNo,1,4);
pNode := oNode.Data;
cPath := pNode^;
if Copy(cPath,1,nLen) = cParentPath then
begin
if Length(cPath) <> nLen then
begin
Self.tbGroups.Append; Self.tbGroups.FieldByName('PointNo').AsString := cPointNo;
Self.tbGroups.FieldByName('PointName').AsString := cPointName;
Self.tbGroups.FieldByName('Paths').AsString := cPath;
Self.tbGroups.FieldByName('PathGroup').AsString := Copy(cPath,1,nLen+4); while oNode.Level > nLevel do
begin
oNode := oNode.Parent;
end; cPointNo := oNode.Text;
cPointName := Copy(cPointNo,6,Length(cPointNo)-5);
cPointNo := Copy(cPointNo,1,4); Self.tbGroups.FieldByName('GroupPointNo').AsString := cPointNo;
Self.tbGroups.FieldByName('GroupPointName').AsString := cPointName; Self.tbGroups.Post;
end;
end;
end;
Self.tbSumList.Close;
Self.tbSumTotal.Close;
Self.tbSumSales.Close;
Self.tbSumOrgan.Close; if Self.tbGroups.RecordCount > 0 then
begin
if dmMain.scMain.AppServer.SumOfPoints(cStartDate,cEndDate,
Self.tbGroups.Data,oSumList,oSumTotal,oSumSales,oSumOrgan) = '1' then
begin
Self.tbSumList.Data := oSumList;
Self.tbSumTotal.Data := oSumTotal;
Self.tbSumSales.Data := oSumSales;
Self.tbSumOrgan.Data := oSumOrgan;
end;
end;
//Self.tbGroups.Close;
Self.SumSortByQty(Sender);
Self.SumSortByMoney(Sender);
end;
这句
if dmMain.scMain.AppServer.SumOfPoints(cStartDate,cEndDate,
Self.tbGroups.Data,oSumList,oSumTotal,oSumSales,oSumOrgan) = '1' then
是提交服务器运行,但是返回的结果很慢,如果开一个线程要怎么处理,由于本人没有用过,请各位大侠指点.
procedure TfrwBillQuery.SumOfOrgan(Sender: TObject);
var
cStartDate: String;
cEndDate: String;
oSumList: Variant;
oSumTotal: Variant;
oSumSales: Variant;
oSumOrgan: Variant;
cPath: String;
cParentPath: String;
cPointNo: String;
cPointName: String;
oNode: TTreenode;
pNode: ^String;
nLen: Integer;
nLevel: Integer;
i: Integer;
begin
cStartDate := DateToStr(Self.dtpStart.Date);
cEndDate := DateToStr(Self.dtpEnd.Date);
gcPointNo := ''; oNode := Self.tvOrgan.Selected;
Self.lblUnitName4.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName3.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName2.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName1.Caption := '统计单位: '+oNode.Text;
Self.lblUnitName.Caption := '统计单位: '+oNode.Text; pNode := oNode.Data;
nLevel := oNode.Level + 1;
cParentPath := pNode^;
nLen := Length(cParentPath); Self.tbGroups.Close;
Self.tbGroups.CreateDataSet; for i := 0 to Self.tvOrgan.Items.Count - 1 do
begin
oNode := Self.tvOrgan.Items.Item[i];
cPointNo := oNode.Text;
cPointName := Copy(cPointNo,6,Length(cPointNo)-5);
cPointNo := Copy(cPointNo,1,4);
pNode := oNode.Data;
cPath := pNode^;
if Copy(cPath,1,nLen) = cParentPath then
begin
if Length(cPath) <> nLen then
begin
Self.tbGroups.Append; Self.tbGroups.FieldByName('PointNo').AsString := cPointNo;
Self.tbGroups.FieldByName('PointName').AsString := cPointName;
Self.tbGroups.FieldByName('Paths').AsString := cPath;
Self.tbGroups.FieldByName('PathGroup').AsString := Copy(cPath,1,nLen+4); while oNode.Level > nLevel do
begin
oNode := oNode.Parent;
end; cPointNo := oNode.Text;
cPointName := Copy(cPointNo,6,Length(cPointNo)-5);
cPointNo := Copy(cPointNo,1,4); Self.tbGroups.FieldByName('GroupPointNo').AsString := cPointNo;
Self.tbGroups.FieldByName('GroupPointName').AsString := cPointName; Self.tbGroups.Post;
end;
end;
end;
Self.tbSumList.Close;
Self.tbSumTotal.Close;
Self.tbSumSales.Close;
Self.tbSumOrgan.Close; if Self.tbGroups.RecordCount > 0 then
begin
if dmMain.scMain.AppServer.SumOfPoints(cStartDate,cEndDate,
Self.tbGroups.Data,oSumList,oSumTotal,oSumSales,oSumOrgan) = '1' then
begin
Self.tbSumList.Data := oSumList;
Self.tbSumTotal.Data := oSumTotal;
Self.tbSumSales.Data := oSumSales;
Self.tbSumOrgan.Data := oSumOrgan;
end;
end;
//Self.tbGroups.Close;
Self.SumSortByQty(Sender);
Self.SumSortByMoney(Sender);
end;
这句
if dmMain.scMain.AppServer.SumOfPoints(cStartDate,cEndDate,
Self.tbGroups.Data,oSumList,oSumTotal,oSumSales,oSumOrgan) = '1' then
是提交服务器运行,但是返回的结果很慢,如果开一个线程要怎么处理,由于本人没有用过,请各位大侠指点.
Self.tbGroups.Data,oSumList,oSumTotal,oSumSales,oSumOrgan) = '1'
这个函数会返回数据集吗?我不知道你们的函数原型。如果不是返回数据集,那么把客户端的所有数据都提交到服务器就不必要了,
可以在客户端重新组合,只把需要的传递过去。同时服务器的这个函数做相应修改
是否需要一次全部取回客户端还是值得商榷的
但是我认为你的瓶颈是在网络传输,不是在单线程。
即使是多线程,还是受到数据传输速度的影响。
我建议你尽量从数据量的大小上来考虑和优化。
TThreadQuery = class(TThread) { 声明线程类 }
private
FDataSet: TDataSet; { 线程中数据集组件 }
procedure DisConnectDataSource;
procedure ConnectDataSource;{ 连接数据集组件和数据感知组件的方法 }
procedure Open;
protected
procedure Execute; override;{ 执行线程的方法 }
public
constructor Create(Query: TDataSet); virtual; { 线程构造器 }
end;{ TThreadQuery类的实现 }{ 连接数据集组件和数据感知组件}
procedure TThreadQuery.DisConnectDataSource;
begin
FDataSet.DisableControls;
end;procedure TThreadQuery.ConnectDataSource;
begin
FDataSet.EnableControls;
end;procedure TThreadQuery.Open;
begin
FDataSet.Open;
end;procedure TThreadQuery.Execute;{ 执行线程的方法 }
begin
try
Synchronize(DisConnectDataSource);
Synchronize(Open);
finally
Synchronize(ConnectDataSource);{ 线程同步 }
end;
end;{ 线程构造器 }
constructor TThreadQuery.Create(Query: TDataSet);
begin
FDataSet := Query; inherited Create(True);
FreeOnTerminate := False;
end;