LazReport, fix record context on which bands are printed after a group change is detected, issue #13165

git-svn-id: trunk@18751 -
This commit is contained in:
jesus 2009-02-18 23:58:06 +00:00
parent ce5bc947cf
commit c84b3499e1
3 changed files with 71 additions and 47 deletions

View File

@ -5,17 +5,17 @@
<Name Value="lazreport"/> <Name Value="lazreport"/>
<Author Value="Olivier Guilbaud, Jesus Reyes A. "/> <Author Value="Olivier Guilbaud, Jesus Reyes A. "/>
<CompilerOptions> <CompilerOptions>
<Version Value="5"/> <Version Value="8"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<SearchPaths> <SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths> </SearchPaths>
<CodeGeneration> <Parsing>
<Generate Value="Faster"/> <SyntaxOptions>
</CodeGeneration> <CStyleOperator Value="False"/>
</SyntaxOptions>
</Parsing>
<Other> <Other>
<CustomOptions Value="
"/>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>

View File

@ -6004,6 +6004,7 @@ var
DetailCount : Integer; DetailCount : Integer;
BooksBkUp : array of TBookRecord; BooksBkUp : array of TBookRecord;
CurGroupValue : variant; CurGroupValue : variant;
BookPrev : pointer;
procedure AddToStack(b: TfrBand); procedure AddToStack(b: TfrBand);
begin begin
@ -6142,43 +6143,55 @@ var
else else
ShowStack; ShowStack;
b.DataSet.Next;
if (Level = 1) and HasGroups then if (Level = 1) and HasGroups then
begin begin
b1 := Bands[btGroupHeader]; // get a bookmark to current record it will be used in case
while b1 <> nil do // a group change is detected and there are remaining group
begin // footers.
curGroupValue := frParser.Calc(b1.GroupCondition); BookPrev := b.DataSet.GetBookMark;
{$IFDEF DebugLR} try
DebugLn('%sGroupCondition=%s curGroupValue=%s LastGroupValue=%s', b.DataSet.Next;
[sspc,b1.GroupCondition,string(b1.LastGroupValue),string(curGroupValue)]); b1 := Bands[btGroupHeader];
{$ENDIF} while b1 <> nil do
if (curGroupValue <> b1.LastGroupValue) or
b.Dataset.Eof then
begin begin
ShowBand(b.FooterBand); curGroupValue := frParser.Calc(b1.GroupCondition);
b2 := Bands[btGroupHeader].LastBand; {$IFDEF DebugLR}
while b2 <> b1 do DebugLn('%sGroupCondition=%s LastGroupValue=%s curGroupValue=%s',
[sspc,b1.GroupCondition,string(b1.LastGroupValue),string(curGroupValue)]);
{$ENDIF}
if (curGroupValue <> b1.LastGroupValue) or
b.Dataset.Eof then
begin begin
ShowBand(b2.FooterBand); // next bands should be printed on the previous record context
b2.Positions[psLocal] := 0; b.DataSet.GotoBookMark(BookPrev);
b2 := b2.Prev; ShowBand(b.FooterBand);
b2 := Bands[btGroupHeader].LastBand;
while b2 <> b1 do
begin
ShowBand(b2.FooterBand);
b2.Positions[psLocal] := 0;
b2 := b2.Prev;
end;
ShowBand(b1.FooterBand);
// advance to the actual current record
b.DataSet.Next;
if not b.Dataset.Eof then
begin
if b1.NewPageAfter then NewPage;
InitGroups(b1);
ShowBand(b.HeaderBand);
b.Positions[psLocal] := 0;
end;
b.ResetLastValues;
break;
end; end;
ShowBand(b1.FooterBand); b1 := b1.Next;
if not b.DataSet.Eof then
begin
if b1.NewPageAfter then NewPage;
InitGroups(b1);
ShowBand(b.HeaderBand);
b.Positions[psLocal] := 0;
end;
b.ResetLastValues;
break;
end; end;
b1 := b1.Next; finally
b.DataSet.FreeBookMark(BookPrev);
end; end;
end; end else
b.DataSet.Next;
if Mode = pmBuildList then if Mode = pmBuildList then
AddRecord(b, rtNext) AddRecord(b, rtNext)

View File

@ -31,6 +31,7 @@ type
FOnOpen, FOnClose: TNotifyEvent; FOnOpen, FOnClose: TNotifyEvent;
FBookmark: TfrBookmark; FBookmark: TfrBookmark;
FEof: Boolean; FEof: Boolean;
function GetSafeDataset: TDataSet;
procedure SetDataSet(Value: TDataSet); procedure SetDataSet(Value: TDataSet);
procedure SetDataSource(Value: TDataSource); procedure SetDataSource(Value: TDataSource);
protected protected
@ -56,7 +57,7 @@ type
published published
property CloseDataSource: Boolean read FCloseDataSource write FCloseDataSource default False; property CloseDataSource: Boolean read FCloseDataSource write FCloseDataSource default False;
property DataSet: TDataSet read FDataSet write SetDataSet; property DataSet: TDataSet read GetSafeDataset write SetDataSet;
property DataSource: TDataSource read FDataSource write SetDataSource; property DataSource: TDataSource read FDataSource write SetDataSource;
property OpenDataSource: Boolean read FOpenDataSource write FOpenDataSource default True; property OpenDataSource: Boolean read FOpenDataSource write FOpenDataSource default True;
property RangeBegin; property RangeBegin;
@ -99,6 +100,16 @@ begin
FDataSource := nil; FDataSource := nil;
end; end;
function TfrDBDataSet.GetSafeDataset: TDataSet;
begin
if FDataSource<>nil then
Result := FDataSource.DataSet
else
Result := nil;
if Result=nil then
Result := FDataset;
end;
procedure TfrDBDataSet.SetDataSource(Value: TDataSource); procedure TfrDBDataSet.SetDataSource(Value: TDataSource);
begin begin
FDataSource := Value; FDataSource := Value;
@ -123,32 +134,32 @@ function TfrDBDataSet.GetBookMark: Pointer;
begin begin
Result:=inherited GetBookMark; Result:=inherited GetBookMark;
if Assigned(fDataSet) then if Assigned(Dataset) then
Result:=fDataSet.GetBookmark; Result:=Dataset.GetBookmark;
end; end;
procedure TfrDBDataSet.GotoBookMark(BM: Pointer); procedure TfrDBDataSet.GotoBookMark(BM: Pointer);
begin begin
if Assigned(fDataSet) then if Assigned(Dataset) then
fDataSet.GotoBookmark(BM); Dataset.GotoBookmark(BM);
end; end;
procedure TfrDBDataSet.FreeBookMark(BM: Pointer); procedure TfrDBDataSet.FreeBookMark(BM: Pointer);
begin begin
if Assigned(fDataSet) and Assigned(BM) then if Assigned(Dataset) and Assigned(BM) then
fDataSet.FreeBookmark(BM); Dataset.FreeBookmark(BM);
end; end;
procedure TfrDBDataSet.DisableControls; procedure TfrDBDataSet.DisableControls;
begin begin
if Assigned(fDataSet) then if Assigned(Dataset) then
fDataSet.DisableControls; Dataset.DisableControls;
end; end;
procedure TfrDBDataSet.EnableControls; procedure TfrDBDataSet.EnableControls;
begin begin
if Assigned(fDataSet) then if Assigned(Dataset) then
fDataSet.EnableControls; Dataset.EnableControls;
end; end;
procedure TfrDBDataSet.Init; procedure TfrDBDataSet.Init;