[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

QReport: Conditional band printing.

Posted on 2000-01-29
3
Medium Priority
?
559 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:spk2000ar
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2414421
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
 

Expert Comment

by:SuperSy
ID: 2478879
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
 

Accepted Solution

by:
JesseJames earned 120 total points
ID: 2479867
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question