Link to home
Start Free TrialLog in
Avatar of light_bulb
light_bulbFlag for United States of America

asked on

Report Builder displays different when run more than once.

Hello,

I have a Report Builder report that I'm trying to dynamically size the height of the detail band.  Here's the code:

If dm.tblOutput.FieldByName('Unique').AsInteger = firstNonZero Then
    Begin
        ppDetailBand1.Height := 0.6979;
        lnOptional.Visible := True;
        lblOptionalPricing.Visible := True;
    End
    Else
    Begin
        lnOptional.Visible := False;
        lblOptionalPricing.Visible := False;
        If dm.tblOutput.FieldByName('Unique').AsInteger > firstNonZero Then
            ppDetailBand1.Height := 0.5000;
    End;

Basically, I'm trying to display/hide a line and a label on the detail band based on the FieldByName('Unique').As Integer value.  If it's greater than firstNonZero, I just hide the label and line and shrink the Height of ppDetailBand1 to 0.5000 to eliminate white space.

This code works perfectly the first time the report is run in my program.  But when it's run more than once, the ppDetailBand1.Height stays at 0.5000, so there's not enough space to display the line and label properly.  I don't understand why it won't reset back to 0.6979 when the report is run a second time??!!

How can I make this work?

Thanks.
Avatar of Limbeck
Limbeck

after you have run it the first time, do you go back to the first record of the dataset? dm.tblOutput.first  ?
Avatar of light_bulb

ASKER

Yes,

Here's the code that sets the firstNonZero variable:

With dm.tblOutput Do
    Begin
        First;
        While Not EOF Do
        Begin
            If FieldByName('Price').AsFloat > 0.00 Then
            Begin
                firstNonZero := FieldByName('Unique').AsInteger;
                Break;
            End
            Else
                firstNonZero := 0;
            Next;
        End;
    End;
hmm and after that you start the report with the last row selected? try a first before you leave the with loop
i never leave a report open by the way, too many weird things can happen. i create it before using it, just to be save
var
qr:=Tqreportsumthing
begin
qr:=Tqreportsumthing.create(self)
with qr do
try
  ...
finally
  free
end
end
The report is run in response to the user clicking a button.  The onClick event for the button is partially shown in my last post.  Before the above code, I have the following:

dm.tblOutput.First;


I think it's starting with the right record.  It's like it will let you change the band height once, but not a second time....
ok, well try creating the report when you need it,and freeing it after you are done with it.
This report is way too complicated (lots of rich text, etc) to have to create it at runtime.  It's heavily based on these rich text controls that are given to me by the marketing department.
hm that is not what i meant. you create your report when you start your application i think, if you look under projectoptions you see that it prob. is autocreated.

an alternative is to create it at runtime, the way i posted earlier. you declare the report as a var (and include the unit name in your uses clause) and do something like this

var
qr:=Tqreportsumthing  //the report
begin
qr:=Tqreportsumthing.create(self)
with qr do
try
  ...
finally
  free
end
end
I'm afraid I'm not following.   The form that the report component is on is not auto created under project options.
can you give me the entire onclick code of the button?
rocedure TdlgCompile.CreateQuoteSheet(alsoShow: Boolean);
Var
    outFile: String;

Begin
    dm.tblOutput.First;

    //if both output formats have been unchecked, check the PDF
    If Not _xFormsAsPDF.Checked And Not _xFormsAsRTF.Checked Then
        _xFormsAsPDF.Checked := True;
    Application.ProcessMessages;

    //figure out first non-zero or included item, and add Optional heading
    //and line to it.  jef 9/5/06
    With dm.tblOutput Do
    Begin
        First;
        While Not EOF Do
        Begin
            If FieldByName('Price').AsFloat > 0.00 Then
            Begin
                firstNonZero := FieldByName('Unique').AsInteger;
                Break;
            End
            Else
                firstNonZero := 0;
            Next;
        End;
    End;

    dm.tblOutput.First;
    // this must take into account if the user wants to generate
    // as a PDF or RTF
    If _xFormsAsRTF.Checked Then
    Begin
        outFile := uFolder + 'QuoteSheet.RTF';
        If Not DirectoryExists(uFolder) Then CreateDir(uFolder);

        With rptOutput Do
        Begin
            AllowPrintToFile := True;
            ShowPrintDialog := False;
            DeviceType := 'RTFFile';
            TextFileName := outFile;
            Print;
        End;
        Application.ProcessMessages;
        If alsoShow Then RunFile(outFile);
    End;

    If _xFormsAsPDF.Checked Then
    Begin
        outFile := uFolder + 'QuoteSheet.PDF';
        If Not DirectoryExists(uFolder) Then CreateDir(uFolder);

        With rptOutput Do
        Begin
            AllowPrintToFile := True;
            ShowPrintDialog := False;
            DeviceType := 'PDFFile';
            TextFileName := outFile;
            Print;
        End;
        Application.ProcessMessages;
        If alsoShow Then RunFile(outFile);
    End;
End;
ok, what i meant was i would create the report here and then free it. next time the user clicks the button again it will create the report and free it again, etc

rocedure TdlgCompile.CreateQuoteSheet(alsoShow: Boolean);
Var
    outFile: String;
   rptoutput:TRptoutput   //

Begin
    dm.tblOutput.First;

    //if both output formats have been unchecked, check the PDF
    If Not _xFormsAsPDF.Checked And Not _xFormsAsRTF.Checked Then
        _xFormsAsPDF.Checked := True;
    Application.ProcessMessages;

    //figure out first non-zero or included item, and add Optional heading
    //and line to it.  jef 9/5/06
    With dm.tblOutput Do
    Begin
        First;
        While Not EOF Do
        Begin
            If FieldByName('Price').AsFloat > 0.00 Then
            Begin
                firstNonZero := FieldByName('Unique').AsInteger;
                Break;
            End
            Else
                firstNonZero := 0;
            Next;
        End;
    End;

    dm.tblOutput.First;
    rptoutput:=TRptoutput.create(Self)    //<-------
 
// this must take into account if the user wants to generate
    // as a PDF or RTF
    If _xFormsAsRTF.Checked Then
    Begin
        outFile := uFolder + 'QuoteSheet.RTF';
        If Not DirectoryExists(uFolder) Then CreateDir(uFolder);

        With rptOutput Do
        Begin
            AllowPrintToFile := True;
            ShowPrintDialog := False;
            DeviceType := 'RTFFile';
            TextFileName := outFile;
            Print;
        End;
        Application.ProcessMessages;
        If alsoShow Then RunFile(outFile);
    End;

    If _xFormsAsPDF.Checked Then
    Begin
        outFile := uFolder + 'QuoteSheet.PDF';
        If Not DirectoryExists(uFolder) Then CreateDir(uFolder);

        With rptOutput Do
        Begin
            AllowPrintToFile := True;
            ShowPrintDialog := False;
            DeviceType := 'PDFFile';
            TextFileName := outFile;
            Print;
        End;
        Application.ProcessMessages;
        If alsoShow Then RunFile(outFile);
    End;
   rptoutput.free   //<------
End;


something like this
Here's what I'm not sure about:

Var
    outFile: String;
   rptoutput:TRptoutput   // how do I define a type for this variable that Delphi will recognize?
ASKER CERTIFIED SOLUTION
Avatar of Limbeck
Limbeck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Report Builder www.digital-metaphors.com

The report's on a form.
Ok, I got it figured out.  On Report Builder, a dynamically sized detail band only moves the bottom margin of the band, not the top.  The items I needed to display/hide were at the top of the band.  So I moved them to the bottom, put them in a region, and set the region to ShifeRelativeTo a rich text control that was also on the detail band.  This worked the way I wanted.

I guess the moral of the story is to remember that dynamically sized detail bands change the bottom margin only when resizing.

Thanks for the help!
ok, glad you figured it out. I dont think i helped, so i would accept a refund of your points :)

btw, if you do want to see what i meant with create and free, here is a little example.

http://www.geocities.com/edje4321/exmpleqrep.zip

No, I won't take a refund.  I pay for unlimited anyway, so.....


Thanks for the example and trying to help me out with this.
no prob :)