How can I resize QRshape so that it can accompany the heigh of my QRlabel?

Hello Guys

I have a report that uses columns and the columns are designed with QRshape.
My problem is when a QRlabel wrap the information and open another line, then my QRshape
doesn't resize too.

I took a picture of the report so that you can see where I have the problem
How can I solve this?

Thank very much
Lista.jpg
LVL 1
hidrauAsked:
Who is Participating?
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
have you tried the QRBand.onBeforePrint event with this line of code :
QRShape.Height:=QRDBText.Height + aConstant_IfNeeded;
?
0
 
hidrauAuthor Commented:
I got this code, but it is missing something to reach the good result.
When I have a wrap with 4 lines, the shape doesn't go to the bottom correctly.
This code came from this link

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21388413.html
procedure TFRelShape.QRDBText1Print(sender: TObject; var Value: String);
var
  lFlags: Longint;
  lRect: TRect;
begin
  lRect.Left:=0;
  lRect.Top:=0;
  lRect.Right :=QRDBText1.width;
  lRect.Bottom:=QRDBText1.Height;
  lFlags:=DT_CALCRECT+DT_LEFT+DT_NOPREFIX+DT_WORDBREAK+DT_EDITCONTROL;

  DrawText(FRelShape.Printer.Canvas.Handle, pChar(value), Length(value), lRect, lFlags);
  qrshape1.height:=lRect.Bottom-lRect.Top;
end;

Open in new window

0
 
bokistCommented:
Hi hidrau!

Do you adjusting detail line height depending on label size?
If not, you can try On_DetailBand_BeforePrint :
    My_QRShape.Height := some_number; // default label.height for one line text  
    if length(trim(My_QRLabel.Caption)) > 46  then My_QRShape.Height := some_number // depending on label.height
If yes,  then simply set shape.height = detailband.height
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
hidrauAuthor Commented:
bokist, did you test the code that I passed?
This is almost working, but something that I don't know to reach a good result.
Have you ever had a problem like this?
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
You mean QRDBText instead of QRLabel ?

I don't have QR here, but I suppose you can resize the shape according to your QRDBText using an onBeforePrint event of your detail band (or something similar)

 QRShape.Height:=QRDBText.Height + aConstant_IfNeeded;
0
 
hidrauAuthor Commented:
yeah epasquier:
I use QRDBText
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
> This is almost working, but something that I don't know to reach a good result.
I suspect that depending on the order of your QR components you placed in your band, the shape might be drawn already when you reach the Print event of the DBText. Which is why a BeforePrint event is best for what you want.
0
 
hidrauAuthor Commented:
well, I just copied the example from the link and adapted it to my code.
Do you have another clue to place this code?
0
 
hidrauAuthor Commented:
Yeah, but nothing.
Did you try my code?
0
 
Emmanuel PASQUIERFreelance Project ManagerCommented:
I can't sorry
here is another thread talking about that subject, and it says it has to change a few detail from yours to make it work, but also tips about what I'm talking about. Maybe you can sort things out
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21572717.html
0
 
hidrauAuthor Commented:
Hello epasquier:

I also tried that, it worked more or less.
The code that I posted here can give better result that this one.
The problem is that when I have 3 / 4 wrap of a text, the QRshape doesn't reach the bottom of the band. Did you get it?
0
 
hidrauAuthor Commented:
Another problem is when I print the page, a line is drawn until the bottom of the page, even though I don't have details rows until the bottom. :((

It is very hard to try to solve this and I need a solution.
0
 
yadapaulCommented:
If the band is the same height as the label, why not just turn on the left frame of the label?  That would also solve your second issue.
0
 
hidrauAuthor Commented:
thanks
0
 
bokistCommented:
Hi hidrau!

I didn't answer your question, because last week I was on holiday.
According your questions : - I didn't tested suggested solution,
                                          - Yes, I had lot of similar problems with QuickReport(I have made over  hundred (or few hundreds)
                                            of different reports and labels, less or more complex with shapes, images, memos..etc,etc. Often, I
                                            must spend lot of time experimenting with quickreport to achieve the goal – usually with success).
                                            Typically the preview and same report printed is different - it is on  you which look is more
                                            important(For me it is always printed report).

You also asked about label and shape size : In case of multiline text, I prefer RichText or Memo  because of it is easier to control the number of lines(at the same time the size).
I made a sample for you - in which you will find an example on your previous post(http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Printing/Q_25852876.html), and also on this question.
Regards,
     Steve
P.s. Sorry on my weak english!
       Sample is made in D7 / QR 4.06
unit Unit_1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Qrctrls, QuickRpt, Db, DBTables, ExtCtrls, Menus, ADODB;

type
  TForm1 = class(TForm)
    QuickRep1: TQuickRep;
    Title_band: TQRBand;
    Header_band: TQRBand;
    Detail_band: TQRBand;
    Summary_band: TQRBand;
    Query: TADOQuery;
    QRLabel1: TQRLabel;
    QRLabel2: TQRLabel;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    Qlbl_1: TQRLabel;
    Qlbl_2: TQRLabel;
    Qlbl_3: TQRLabel;
    Title_text: TQRLabel;
    Title_Shape: TQRShape;
    QRShape_1: TQRShape;
    QRShape_2: TQRShape;
    QRShape_3: TQRShape;
    QRShape_4: TQRShape;
    QRShape1: TQRShape;
    QRText: TQRRichText;
    procedure FormCreate(Sender: TObject);
    procedure Title_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
    procedure Title_bandAfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
    procedure Header_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
    procedure Detail_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
    procedure Summary_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
    procedure Summary_bandAfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Read_count : integer = 0;
  Title_printed : boolean = False;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  // sample table : prod_id char(10), prod_name char(100), price float
  with Query do
     begin
     Close;
     Sql.clear;
     Sql.add('Select prod_id, prod_name, price from my_table');
     Sql.Add(' order by prod_id');
     Open;
  end;
end;

procedure TForm1.Title_bandBeforePrint(Sender: TQRCustomBand;  var PrintBand: Boolean);
begin
   Title_shape.Height := round(QuickRep1.Height / 2);
   Title_text.Top := round((QuickRep1.Height / 2) - (Title_text.Height / 2));
   Title_shape.Top := round((QuickRep1.Height / 2) - (Title_shape.Height / 2));
   PrintBand := not Title_printed;
end;

procedure TForm1.Title_bandAfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
begin
   Title_printed := True;
   QuickRep1.NewPage;
   QuickRep1.Options := [FirstPageHeader, LastPageFooter];
end;

procedure TForm1.Header_bandBeforePrint(Sender: TQRCustomBand;  var PrintBand: Boolean);
begin
   PrintBand := Title_printed;
end;

procedure TForm1.Detail_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
var
  i, x, y, number_of_lines : integer;

  Function Line_count:integer;
  begin
     x := 0;
     y := 0;
     repeat
       if length(trim(QRText.Lines[x])) > 0 then  inc(y);
       inc(x);
     until x = QRText.Lines.Count;
     Result := y;
  end;

begin
  inc(Read_count);
  QRText.Lines.Clear;
  Qlbl_1.Caption := inttostr(Read_count) + '.';
  Qlbl_2.Caption := Query.fieldbyname('prod_id').asstring;
  Qlbl_3.Caption := floattostr(Query.fieldbyname('price').asfloat);
  QRText.Lines.Text := trim(Query.fieldbyname('prod_name').asstring);
  number_of_lines := Line_count;
  QRText.Height := 17 * number_of_lines;
  Detail_band.Height := QRText.Height + 2;
  if number_of_lines > 1 then  Detail_band.Height := Detail_band.Height - round(number_of_lines * 1.4);
  for i := 1 to 4 do
      with Form1.FindComponent('QRShape_' + IntToStr(i)) as TQRShape do Height := Detail_band.Height + 1;
end;

procedure TForm1.Summary_bandBeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean);
begin
   PrintBand := Title_printed;
end;

procedure TForm1.Summary_bandAfterPrint(Sender: TQRCustomBand; BandPrinted: Boolean);
var
  i : integer;
begin
// set default values - this part is needed ONLY if you are printing from preview
  if BandPrinted then
     begin
     Read_count := 0;
     QRText.Width := 125;
     QRText.Height := 17;
     Title_printed := False;
     Detail_band.Height :=  22;
     QuickRep1.Options := [LastPageFooter];
     for i := 1 to 4 do
        with Form1.FindComponent('QRShape_' + IntToStr(i)) as TQRShape do Height := Detail_band.Height + 1;
  end;
end;

end.

Open in new window

Form1.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.