Recent

Author Topic: PowerPDF in lazarus 1.2 - PRGridpanel not generating all the lines in the PDF  (Read 4285 times)

drkppvch

  • New Member
  • *
  • Posts: 13
Hello,

I have a project that connects to a firebird database and get invoice details.

Using one of the original sample projects from PowerPDF for Delphi, I manage to create a lazarus project that generates and invoice PDF.

I create the PDF using the following code:

 
Code: Pascal  [Select]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2.  begin
  3.     if SaveDialog1.Execute then
  4.     begin
  5.       Screen.Cursor := crHourGlass;
  6.       Application.ProcessMessages;
  7.       PRImage1.Printable := true;
  8.       PRLabel1.Printable := true;
  9.       PRLabel2.Printable := true;
  10.       PRLabel3.Printable := true;
  11.       PRLabel4.Printable := true;
  12.       PRLabel5.Printable := true;
  13.       PRLabel6.Printable := true;
  14.       PRLabel7.Printable := true;
  15.       PRLabel8.Printable := true;
  16.       PRLabel9.Printable := true;
  17.       PRLabel10.Printable := true;
  18.       PRLabel11.Printable := true;
  19.       PRLabel12.Printable := true;
  20.       PRLabel13.Printable := true;
  21.       PRLabel20.Printable := true;
  22.       PRText1.Printable := true;
  23.       PRText2.Printable := true;
  24.       PRText3.Printable := true;
  25.       PRText4.Printable := true;
  26.       PRText5.Printable := true;
  27.       PRText6.Printable := true;
  28.       PRText7.Printable := true;
  29.       PRText8.Printable := true;
  30.       PRText9.Printable := true;
  31.       PRText10.Printable := true;
  32.       PRText11.Printable := true;
  33.       PRText13.Printable := true;
  34.       PRText12.Printable := true;
  35.       try
  36.         with PReport1 do
  37.         begin
  38.           FileName := SaveDialog1.FileName;
  39.  
  40.           // starting printing document.
  41.            BeginDoc;
  42.  
  43.  
  44.  //       SQLQuery2.Open;
  45.  //         while not SQLQuery2.Eof do
  46.           Print(PRPage1);
  47.  
  48.         // save document.
  49.         EndDoc;
  50.  
  51.      //  SQLQuery2.Close;
  52.       end;
  53.  
  54.       finally
  55.         Screen.Cursor := crDefault;
  56.       end;
  57.   end;
  58.  
  59.  end;

My invoices contain a sub table called invoice lines which contain the description, Qty, Net Value, etc.

One invoice can have one or more of this lines and the sum of all the lines give me the invoice total.

With the above code I can generate the PDF with no problem as long as I have one invoice line in the invoice, If I have multiple lines only the first one shows up on the PDF.

If I change this portion of the code as follows

Code: Pascal  [Select]
  1. try
  2.         with PReport1 do
  3.         begin
  4.           FileName := SaveDialog1.FileName;
  5.  
  6.           // starting printing document.
  7.            BeginDoc;
  8.  
  9.  
  10.        SQLQuery2.Open;
  11.         while not SQLQuery2.Eof do
  12.           Print(PRPage1);
  13.  
  14.         // save document.
  15.         EndDoc;
  16.  
  17.      SQLQuery2.Close;
  18.       end;
  19.  
  20.       finally
  21.         Screen.Cursor := crDefault;
  22.       end;
  23.   end;
  24.  
  25.  end;  

the lazarus debugger crashes and the PDF is not generated, this part of the code is supposed to populate the other rows in the PRGidpanel.

The original Delphi code Stated:

Code: Pascal  [Select]
  1.         try
  2.       with PReport1 do
  3.       begin
  4.         FileName := SaveDialog1.FileName;
  5.  
  6.         // starting printing document.
  7.         BeginDoc;
  8.  
  9.         Table1.Open;
  10.         while not Table1.Eof do
  11.           Print(PRPage1);
  12.  
  13.         // save document.
  14.         EndDoc;
  15.         Table1.Close;
  16.       end;
  17.     finally
  18.       Screen.Cursor := crDefault;
  19.     end;
  20.   end;
  21. end;    

I change it from Table1 to SQLQuery2.

The Original Delphi PRGridpanel code was:

Code: Pascal  [Select]
  1. procedure TForm1.PRGridPanel1BeforePrintChild(Sender: TObject;
  2.   ACanvas: TPRCanvas; ACol, ARow: Integer; Rect: TRect);
  3. begin
  4.   with Table1 do
  5.     if not Table1.Eof then
  6.     begin
  7.       // setting text from current record.
  8.       TxtCustNo.Text := Table1CustNo.AsString;
  9.       TxtCompany.Text := Table1Company.AsString;
  10.       TxtAddr.Text := Table1Addr1.AsString;
  11.       TxtCity.Text := Table1City.AsString;
  12.       TxtState.Text := Table1State.AsString;
  13.  
  14.       // move next current record.
  15.       Table1.Next;
  16.     end
  17.     else
  18.     begin
  19.       TxtCustNo.Printable := false;
  20.       TxtCompany.Printable := false;
  21.       TxtAddr.Printable := false;
  22.       TxtCity.Printable := false;
  23.       TxtState.Printable := false;
  24.     end;
  25. end;

And My lazarus code after the change looks like this:

Code: Pascal  [Select]
  1. procedure TForm1.PRGridPanel1BeforePrintChild (Sender: TObject;
  2.   ACanvas: TPRCanvas; ACol, ARow: Integer; Rect: TRect);
  3. begin
  4.   with SQLQuery2 do
  5.     if not SQLQuery2.Eof then
  6.     begin
  7.       // setting text from current record.
  8.       PRText9.Text := SQLQuery2.FieldByName('Description').asString;
  9.       PRText10.Text := SQLQuery2.FieldByName('QTY').asString;
  10.       PRText11.Text := SQLQuery2.FieldByName('TAX').asString;
  11.       PRText13.Text := SQLQuery2.FieldByName('VAL_LINE').asString;
  12.        // move next current record.
  13.       SQLQuery2.Next;
  14.      end
  15.     else
  16.     begin
  17.       PRText9.Printable := false;
  18.       PRText10.Printable := false;
  19.       PRText11.Printable := false;
  20.       PRText13.Printable := false;
  21.     end;
  22. end;  

This is the code that I am assuming will handled the PRGridpanel in lazarus but it is not working properly for me and I can not find a way to fix it.

Does anyone has any idea on how to fix my code or if you have a working sample PowerPDF code for lazarus with multiple lines in the PRGridpanel from a database please post the code.

Sincerely Drkpp

drkppvch

  • New Member
  • *
  • Posts: 13
HI,

I found a solution in a Delphi tutorial PDF written in Portuguese, but the code can be followed very easily or you can use google translate (I don't speak Portuguese and it worked for me).

Go to page 8 of the pdf and that is where the tutorial for PowerPDF start.

http://www.theclub.com.br/restrito/revistas/PDFS/2011/1110.pdf