Browse Source

* Fix data fetching optimization

git-svn-id: trunk@37501 -
michael 7 years ago
parent
commit
9e08dd108b
2 changed files with 26 additions and 19 deletions
  1. 1 0
      packages/fcl-report/demos/rptnestedgroups.pp
  2. 25 19
      packages/fcl-report/src/fpreport.pp

+ 1 - 0
packages/fcl-report/demos/rptnestedgroups.pp

@@ -117,6 +117,7 @@ begin
   rec := TStringList.Create;
   rec := TStringList.Create;
   rec.Delimiter := ';';
   rec.Delimiter := ';';
   rec.StrictDelimiter := true;
   rec.StrictDelimiter := true;
+  rec.DelimitedText := sl[0]; // RecNo is 0
 end;
 end;
 
 
 procedure TNestedGroupsDemo.CreateReportDesign;
 procedure TNestedGroupsDemo.CreateReportDesign;

+ 25 - 19
packages/fcl-report/src/fpreport.pp

@@ -366,6 +366,8 @@ type
     FPrevValue: variant;
     FPrevValue: variant;
     FOnGetUsePrevValue: TFPReportQueryUsePrevValue;
     FOnGetUsePrevValue: TFPReportQueryUsePrevValue;
     FExprIdentierDef: TFPExprIdentifierDef;
     FExprIdentierDef: TFPExprIdentifierDef;
+  Protected
+    Procedure InitValue(SavePrevious : Boolean); virtual;
   public
   public
     property OnGetUsePrevValue: TFPReportQueryUsePrevValue read FOnGetUsePrevValue write FOnGetUsePrevValue;
     property OnGetUsePrevValue: TFPReportQueryUsePrevValue read FOnGetUsePrevValue write FOnGetUsePrevValue;
     property ExprIdentierDef: TFPExprIdentifierDef read FExprIdentierDef write FExprIdentierDef;
     property ExprIdentierDef: TFPExprIdentifierDef read FExprIdentierDef write FExprIdentierDef;
@@ -413,6 +415,7 @@ type
     function GetFieldValue(AFieldName: string): variant;
     function GetFieldValue(AFieldName: string): variant;
     function GetFieldWidth(AFieldName: string): integer;
     function GetFieldWidth(AFieldName: string): integer;
     function GetLastFieldValue(AFieldName: string): variant;
     function GetLastFieldValue(AFieldName: string): variant;
+    procedure InitFieldValues(SavePrevious: Boolean);
     procedure SetDataFields(const AValue: TFPReportDataFields);
     procedure SetDataFields(const AValue: TFPReportDataFields);
   protected
   protected
     function CreateDataFields: TFPReportDataFields; virtual;
     function CreateDataFields: TFPReportDataFields; virtual;
@@ -9012,6 +9015,15 @@ begin
     TFPReportDatafields(Collection).ReportData.DoGetValue(FieldName, Result);
     TFPReportDatafields(Collection).ReportData.DoGetValue(FieldName, Result);
 end;
 end;
 
 
+procedure TFPReportDataField.InitValue(SavePrevious: Boolean);
+begin
+  if Not SavePrevious then
+    FPrevValue := nil
+  else
+    FPrevValue := FValue;
+  FValue:=GetValue;
+end;
+
 procedure TFPReportDataField.GetRTValue(Var Result: TFPExpressionResult;
 procedure TFPReportDataField.GetRTValue(Var Result: TFPExpressionResult;
   ConstRef AName: ShortString);
   ConstRef AName: ShortString);
 
 
@@ -9222,9 +9234,6 @@ end;
 
 
 procedure TFPReportData.Open;
 procedure TFPReportData.Open;
 
 
-var
-  I: Integer;
-
 begin
 begin
   if Assigned(FOnOpen) then
   if Assigned(FOnOpen) then
     FOnOpen(Self);
     FOnOpen(Self);
@@ -9232,28 +9241,28 @@ begin
   InitFieldDefs;
   InitFieldDefs;
   FIsOpened := True;
   FIsOpened := True;
   FRecNo := 1;
   FRecNo := 1;
-  for I := 0 to FDataFields.Count - 1 do
-  begin
-    FDataFields[I].FValue := FDataFields[I].GetValue;
-    FDataFields[I].FPrevValue := nil;
-  end;
+  If not EOF then
+    InitFieldValues(false);
 end;
 end;
 
 
-procedure TFPReportData.First;
+procedure TFPReportData.InitFieldValues(SavePrevious : Boolean);
 
 
 var
 var
   I: Integer;
   I: Integer;
 
 
+begin
+  for I := 0 to FDataFields.Count - 1 do
+    FDataFields[i].InitValue(SavePrevious);
+end;
+
+procedure TFPReportData.First;
+
 begin
 begin
   if Assigned(FOnFirst) then
   if Assigned(FOnFirst) then
     FOnFirst(Self);
     FOnFirst(Self);
   DoFirst;
   DoFirst;
   FRecNo := 1;
   FRecNo := 1;
-  for I := 0 to FDataFields.Count - 1 do with FDataFields[I] do
-  begin
-    FValue := GetValue;
-    FPrevValue := nil;
-  end;
+  InitFieldValues(False);
 end;
 end;
 
 
 procedure TFPReportData.Next;
 procedure TFPReportData.Next;
@@ -9264,11 +9273,8 @@ begin
   if Assigned(FOnNext) then
   if Assigned(FOnNext) then
     FOnNext(Self);
     FOnNext(Self);
   DoNext;
   DoNext;
-  for I := 0 to FDataFields.Count - 1 do
-  begin
-  FDataFields[I].FPrevValue := FDataFields[I].FValue;
-    FDataFields[I].FValue := FDataFields[I].GetValue;
-  end;
+  if not EOF then
+    InitFieldValues(True);
 end;
 end;
 
 
 procedure TFPReportData.Close;
 procedure TFPReportData.Close;