Avatar of light_bulb
light_bulb
Flag 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.
Delphi

Avatar of undefined
Last Comment
Limbeck

8/22/2022 - Mon
Limbeck

after you have run it the first time, do you go back to the first record of the dataset? dm.tblOutput.first  ?
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;
Limbeck

hmm and after that you start the report with the last row selected? try a first before you leave the with loop
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Limbeck

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
light_bulb

ASKER
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....
Limbeck

ok, well try creating the report when you need it,and freeing it after you are done with it.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
light_bulb

ASKER
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.
Limbeck

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
light_bulb

ASKER
I'm afraid I'm not following.   The form that the report component is on is not auto created under project options.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Limbeck

can you give me the entire onclick code of the button?
light_bulb

ASKER
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;
Limbeck

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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
light_bulb

ASKER
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
Limbeck

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
light_bulb

ASKER
Report Builder www.digital-metaphors.com

The report's on a form.
light_bulb

ASKER
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!
Your help has saved me hundreds of hours of internet surfing.
fblack61
Limbeck

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

light_bulb

ASKER
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.
Limbeck

no prob :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.