QReport: Conditional band printing.

I've this data structure:

table tA with fields A,B,C,D,E of any type.

I need to print with QReport something like this:

Title Band
Group Band  (field A)
Detail Band (*)
GroupFooter Band
PageFooter Band

(*) in the detail band i need to print
    C or D or E or (C,D) or (C,E) or (D,E)
    depending on the value of B

How can i do this?
Is there any way to create all posible detail bands and show only what i need?
Perhaps i can do this trough the OnPrint event but do i have to create each component in the detail band at runtime depending on what to print?
I'm using Delphi 5 with QReport 3.0.5.
Thanks to you all,
Martin
LVL 4
Martin BarredaLic. in Computer ScienceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi spk2000ar,

each TQRDBText has an onprint-event, which you can use like

//Sample for C
procedure TForm1.QRDBText1Print(sender: TObject;
                                var Value: String);
begin
  if qrdbtext1.DataSet.FieldByName('B').AsString = 'WhatEver' then
    Value := ''  //do not print
  else
    Value := qrdbtext1.DataSet.FieldByName('C').AsString;  //print
end;


or use use a TQRLabel for the textvariants
and use the DetailBand.OnBefroePrint event like

procedure TForm1.QRBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  if Table1.FieldByName('B').AsString = 'WhatEver' then
    QRLabel1.Text := Table1.FieldByName('C').AsString else
  if Table1.FieldByName('B').AsString = 'SomeOther' then
    QRLabel1.Text := '('+Table1.FieldByName('C').AsString+
                     ','+Table1.FieldByName('C').AsString+')' else
  if Table1.FieldByName('B').AsString = 'OtherThing' then
    QRLabel1.Text := Table1.FieldByName('D').AsString else
  // and so on
end;

meikl
0
SuperSyCommented:
Martin;

There is a simple AND messy way to show only the things you want to show in a band --- you can set "Enabled" property to True or False.  

However, obviously, you have to have all the necessary components in the band (most likely overlapping each other and extremely difficult to edit if at all possible).  You can keep them all Enabled = False and turn a group of them to True in the BandBeforePrint according to B.

Principle is simple, but doing it is very messy, but if you have only three choices, it could be viable.  

Hope this helps.  

Sy
0
JesseJamesCommented:
I did this:

Put a qrExpr component in the detailband
(It is in the Qreport component pallete)

On Expression property of it you can type the following command (of course it´s an example)


if(tA.B = value1,tA.C,if(tA.B = value2,tA.D,if(tA.B = value3,tA.E,if(tA.B = value4,(tA.C,tA.D),(C,E)))))

this works like:

if(tA.B = value1) then
   print tA.C
else if(tA.B = value2 then
   print tA.D
else if(tA.B = value3 then
   print tA.E
else if(tA.B = value4 then
   print (tA.C,tA.D)
else print (C,E)

the Expr component print any value (number or character) and you can do things like (put in expression property):


´The value of B is: '+tA.B+´ so the result is: ´+if(tA.B = value1,tA.C,if(tA.B = value2,tA.D,if(tA.B = value3,tA.E,if(tA.B = value4,(tA.C,tA.D),(C,E)))))

I did this and it works!


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.