Expand All & Duplicate Labels in Subreports
Hi,
I wondered if anyone could shed some light on two problems I'm having at
present.
The first is related to the ExpandAll function for DrillDown subreports.
What I'm interested in is to be able to collapse individual subreports after
an ExpandAll call, as well as the opposite (i.e. expanding individual
subreports after setting ExpandAll to false). I've already had some
correspondence with Jim Bennett from DigitalMetaphors about this, and he was
kind enough to send me an example file (ReverseDrillDowns.zip). However,
I'm not sure this demo does exactly what I want - please excuse me if I'm
just being a bit dim.
The example expanded all subreports on the launch of the main report in such
a way that each could be expanded and collapsed individually. What I've got
is lots of nested drilldown subreports that can all be collapsed and
expanded individually.. However I wanted to add two `buttons' (actually I
was going to use a label's DrawCommandClick event), one to expand all nested
subreports and one to collapse them all. When I originally tried this
merely using the report's ExpandAll property I found out via this newsgroup
that you couldn't by default expand individual subreports separately once
you'd set ExpandAll to false (or the opposite - collapsing individual
subreports following an ExpandAll). I can see that the ReverseDrillDowns
example works well when expanding all subreports at the start, but when I
try to replicate the key code in the appropriate event, it doesn't seem to
work:
{---------------------------------------------------------------------------
---}
{ TForm1.CreateExpansions }
{ Loops through list of subreport instance ExpansionKeys to create
expansion
for each. Note that when ExpandAll is set to True, no expansions are
created
so we use this method to force the expansions to be created. }
procedure TForm1.CreateExpansions;
var
liIndex: Integer;
begin
for liIndex := 0 to FSubreportList.Count - 1 do
ppSubReport1.AddExpansion(FSubreportList[liIndex]);
end; { procedure, CreateExpansions }
{---------------------------------------------------------------------------
---}
{ TForm1.FormCreate }
procedure TForm1.FormCreate(Sender: TObject);
begin
FSubreportList := TStringList.Create;
end; { procedure, FormCreate }
{---------------------------------------------------------------------------
---}
{ TForm1.FormDestroy }
procedure TForm1.FormDestroy(Sender: TObject);
begin
FSubreportList.Free;
end; { procedure, FormDestroy }
{---------------------------------------------------------------------------
---}
{ TForm1.ppReport1BeforePrint }
procedure TForm1.ppReport1BeforePrint(Sender: TObject);
begin
FSubreportList.Clear;
FExpansionComplete := False;
end; { procedure, ppReport1BeforePrint }
{---------------------------------------------------------------------------
---}
{ TForm1.ppReport1EndFirstPass }
{ We only want to create all the expansions once, so we check
FExpansionComplete.
Once we are through with this, we need to set PassSetting back to
psOnePass
so we don't regenerate the report everytime a subreport is expanded or
collapsed. }
procedure TForm1.ppReport1EndFirstPass(Sender: TObject);
begin
if not FExpansionComplete then begin
ppSubreport1.ExpandAll := False;
CreateExpansions;
ppReport1.PassSetting := psOnePass;
FExpansionComplete := True;
end;
end; { procedure, ppReport1EndFirstPass }
{---------------------------------------------------------------------------
---}
{ TForm1.ppSubReport1Print }
{ Each time the expanded subreport prints, get its ExpansionKey and add it
to
the list. }
procedure TForm1.ppSubReport1Print(Sender: TObject);
begin
if not ((ppSubReport1.Overflow) and (FExpansionComplete)) then
FSubreportList.Add(ppSubReport1.GetExpansionKey);
end; { procedure, ppSubReport1Print }
procedure TForm1.ppLabel1DrawCommandClick(Sender, aDrawCommand: TObject);
begin
ppSubreport1.ExpandAll := False;
CreateExpansions;
ppReport1.Reset;
end;
Nothing happens when I click on the label in the preview form; what am I
doing wrong? It's also not clear from the example how to collapse
individual subreports (i.e. what's the opposite of the AddExpansion call?).
The other (unrelated) problem I've got - and sorry to go on for so long - is
to do with one of my subreports.
It;s just got a region with some labels in, but everything appears twice
when the subreport is expanded. There appears to be no rhyme or reason for
this, as I've got two similar subreports, on containing the problem one and
one contained by it. Both of these only show their regions and labels once.
I've even tried cutting and pasting the region from one OK subreport to the
problem one, but everything is still duplicated. Have you any idea what can
be causing this behaviour?
Thanks for any light you can shed on these matters.
Regards,
Terry Hoggart
I wondered if anyone could shed some light on two problems I'm having at
present.
The first is related to the ExpandAll function for DrillDown subreports.
What I'm interested in is to be able to collapse individual subreports after
an ExpandAll call, as well as the opposite (i.e. expanding individual
subreports after setting ExpandAll to false). I've already had some
correspondence with Jim Bennett from DigitalMetaphors about this, and he was
kind enough to send me an example file (ReverseDrillDowns.zip). However,
I'm not sure this demo does exactly what I want - please excuse me if I'm
just being a bit dim.
The example expanded all subreports on the launch of the main report in such
a way that each could be expanded and collapsed individually. What I've got
is lots of nested drilldown subreports that can all be collapsed and
expanded individually.. However I wanted to add two `buttons' (actually I
was going to use a label's DrawCommandClick event), one to expand all nested
subreports and one to collapse them all. When I originally tried this
merely using the report's ExpandAll property I found out via this newsgroup
that you couldn't by default expand individual subreports separately once
you'd set ExpandAll to false (or the opposite - collapsing individual
subreports following an ExpandAll). I can see that the ReverseDrillDowns
example works well when expanding all subreports at the start, but when I
try to replicate the key code in the appropriate event, it doesn't seem to
work:
{---------------------------------------------------------------------------
---}
{ TForm1.CreateExpansions }
{ Loops through list of subreport instance ExpansionKeys to create
expansion
for each. Note that when ExpandAll is set to True, no expansions are
created
so we use this method to force the expansions to be created. }
procedure TForm1.CreateExpansions;
var
liIndex: Integer;
begin
for liIndex := 0 to FSubreportList.Count - 1 do
ppSubReport1.AddExpansion(FSubreportList[liIndex]);
end; { procedure, CreateExpansions }
{---------------------------------------------------------------------------
---}
{ TForm1.FormCreate }
procedure TForm1.FormCreate(Sender: TObject);
begin
FSubreportList := TStringList.Create;
end; { procedure, FormCreate }
{---------------------------------------------------------------------------
---}
{ TForm1.FormDestroy }
procedure TForm1.FormDestroy(Sender: TObject);
begin
FSubreportList.Free;
end; { procedure, FormDestroy }
{---------------------------------------------------------------------------
---}
{ TForm1.ppReport1BeforePrint }
procedure TForm1.ppReport1BeforePrint(Sender: TObject);
begin
FSubreportList.Clear;
FExpansionComplete := False;
end; { procedure, ppReport1BeforePrint }
{---------------------------------------------------------------------------
---}
{ TForm1.ppReport1EndFirstPass }
{ We only want to create all the expansions once, so we check
FExpansionComplete.
Once we are through with this, we need to set PassSetting back to
psOnePass
so we don't regenerate the report everytime a subreport is expanded or
collapsed. }
procedure TForm1.ppReport1EndFirstPass(Sender: TObject);
begin
if not FExpansionComplete then begin
ppSubreport1.ExpandAll := False;
CreateExpansions;
ppReport1.PassSetting := psOnePass;
FExpansionComplete := True;
end;
end; { procedure, ppReport1EndFirstPass }
{---------------------------------------------------------------------------
---}
{ TForm1.ppSubReport1Print }
{ Each time the expanded subreport prints, get its ExpansionKey and add it
to
the list. }
procedure TForm1.ppSubReport1Print(Sender: TObject);
begin
if not ((ppSubReport1.Overflow) and (FExpansionComplete)) then
FSubreportList.Add(ppSubReport1.GetExpansionKey);
end; { procedure, ppSubReport1Print }
procedure TForm1.ppLabel1DrawCommandClick(Sender, aDrawCommand: TObject);
begin
ppSubreport1.ExpandAll := False;
CreateExpansions;
ppReport1.Reset;
end;
Nothing happens when I click on the label in the preview form; what am I
doing wrong? It's also not clear from the example how to collapse
individual subreports (i.e. what's the opposite of the AddExpansion call?).
The other (unrelated) problem I've got - and sorry to go on for so long - is
to do with one of my subreports.
It;s just got a region with some labels in, but everything appears twice
when the subreport is expanded. There appears to be no rhyme or reason for
this, as I've got two similar subreports, on containing the problem one and
one contained by it. Both of these only show their regions and labels once.
I've even tried cutting and pasting the region from one OK subreport to the
problem one, but everything is still duplicated. Have you any idea what can
be causing this behaviour?
Thanks for any light you can shed on these matters.
Regards,
Terry Hoggart
This discussion has been closed.
Comments
The feature that you want isn't included in RB. RB is very flexible, so it
may be possible to code it outside of RB's library.
You're not dim, the fact is that my custom coded "tip" doesn't quite work
correctly all the time:) When we're doing tech support, we try to put
ourselves in your shoes in order to get you something to work with even if
RB can't do it out of the box. We may decide that we could code around the
problem with a tip which bends RB a little this way and that way, but we're
just trying to get you a possible solution instead of saying that it isn't
doable in RB and we won't code it. Pretty much anyting is possible in RB
because it is so flexible. We know that it is very flexible and so sometimes
we feel like we could code the feature request in a half hour or so, and may
decide we make an attempt at it just to see what we can code. One day I
coded DrillDownHistory.
http://www.digital-metaphors.com/tips/DrillDownHistory.zip Sometime later,
and feeling confident, the ExpandAll/Collapse question came up and I made
some progress, but not quite getting it finished in a good fully functional
tip. http://www.digital-metaphors.com/tips/DrillDownExpandAllProj.zip
The tip does show that you can control the keys, and that you can control
the engine to regenerate pages as the drill downs are expanded and
collapsed. By default, ExpandAll is exactly that, it expands all the
subreports and they are only shown that way. The subreports are not
recollapsable in RB out of the box using the ExpandAll feature. When I made
this tip I was shooting from the hip and came up with the KeyMaster class.
It doesn't work quite right yet, but it is a good head start. I looked at it
again breifly today and made a TppPrintPreview replacement to surface the
TppPreviewPlugin object to get at the KeyMaster. I've pointed you towards
the latest project I have, which should run, but there are some bugs in this
tip. I'll give it to you to examine and let me know if you can take it and
get it working. I'll be more than happy to help answer any questions or
point you in the right direction, but as far as coding more of it, we'd
really need to examine the other feature request and prioritize them before
coding any features which take significant effort all the way to Digital
Metaphors standards. Thankyou for your understanding.
You second problem is probably related to the report engine being confused
about the bookmarks it has on the dataset. I didn't closely examine you
code, but I think it is related. If the bookmarks are screwed up, thenthe
report engine may think there are multiple records when there is really only
one. You'd have to provide an example to support@digital-metaphors.com for
us to debug without the expand all logic included.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Thanks very much for taking the time and trouble to give me such a detailed
answer.
To deal with the second problem first, I've actually made that go away by
disconnecting the subreport from the datapipeline at design time (all the
components were TppLabels that had the text assigned dynamically by their
GetText methods anyway). No idea why that worked, but it's fine now anyhow.
As for the other matter, thanks for drawing my attention to those other
examples of yours. I'll have a look at them and let you know how I get on.
I'm currently still using RB6 although I have purchased RB7 now, but it
looks like from your reply that this feature is not available in RB7 either
then?
Regards,
Terry Hoggart
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com