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:
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Screen.Cursor := crHourGlass;
Application.ProcessMessages;
PRImage1.Printable := true;
PRLabel1.Printable := true;
PRLabel2.Printable := true;
PRLabel3.Printable := true;
PRLabel4.Printable := true;
PRLabel5.Printable := true;
PRLabel6.Printable := true;
PRLabel7.Printable := true;
PRLabel8.Printable := true;
PRLabel9.Printable := true;
PRLabel10.Printable := true;
PRLabel11.Printable := true;
PRLabel12.Printable := true;
PRLabel13.Printable := true;
PRLabel20.Printable := true;
PRText1.Printable := true;
PRText2.Printable := true;
PRText3.Printable := true;
PRText4.Printable := true;
PRText5.Printable := true;
PRText6.Printable := true;
PRText7.Printable := true;
PRText8.Printable := true;
PRText9.Printable := true;
PRText10.Printable := true;
PRText11.Printable := true;
PRText13.Printable := true;
PRText12.Printable := true;
try
with PReport1 do
begin
FileName := SaveDialog1.FileName;
// starting printing document.
BeginDoc;
// SQLQuery2.Open;
// while not SQLQuery2.Eof do
Print(PRPage1);
// save document.
EndDoc;
// SQLQuery2.Close;
end;
finally
Screen.Cursor := crDefault;
end;
end;
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
try
with PReport1 do
begin
FileName := SaveDialog1.FileName;
// starting printing document.
BeginDoc;
SQLQuery2.Open;
while not SQLQuery2.Eof do
Print(PRPage1);
// save document.
EndDoc;
SQLQuery2.Close;
end;
finally
Screen.Cursor := crDefault;
end;
end;
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:
try
with PReport1 do
begin
FileName := SaveDialog1.FileName;
// starting printing document.
BeginDoc;
Table1.Open;
while not Table1.Eof do
Print(PRPage1);
// save document.
EndDoc;
Table1.Close;
end;
finally
Screen.Cursor := crDefault;
end;
end;
end;
I change it from Table1 to SQLQuery2.
The Original Delphi PRGridpanel code was:
procedure TForm1.PRGridPanel1BeforePrintChild(Sender: TObject;
ACanvas: TPRCanvas; ACol, ARow: Integer; Rect: TRect);
begin
with Table1 do
if not Table1.Eof then
begin
// setting text from current record.
TxtCustNo.Text := Table1CustNo.AsString;
TxtCompany.Text := Table1Company.AsString;
TxtAddr.Text := Table1Addr1.AsString;
TxtCity.Text := Table1City.AsString;
TxtState.Text := Table1State.AsString;
// move next current record.
Table1.Next;
end
else
begin
TxtCustNo.Printable := false;
TxtCompany.Printable := false;
TxtAddr.Printable := false;
TxtCity.Printable := false;
TxtState.Printable := false;
end;
end;
And My lazarus code after the change looks like this:
procedure TForm1.PRGridPanel1BeforePrintChild (Sender: TObject;
ACanvas: TPRCanvas; ACol, ARow: Integer; Rect: TRect);
begin
with SQLQuery2 do
if not SQLQuery2.Eof then
begin
// setting text from current record.
PRText9.Text := SQLQuery2.FieldByName('Description').asString;
PRText10.Text := SQLQuery2.FieldByName('QTY').asString;
PRText11.Text := SQLQuery2.FieldByName('TAX').asString;
PRText13.Text := SQLQuery2.FieldByName('VAL_LINE').asString;
// move next current record.
SQLQuery2.Next;
end
else
begin
PRText9.Printable := false;
PRText10.Printable := false;
PRText11.Printable := false;
PRText13.Printable := false;
end;
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