How to send images in a Fastreport report with Delphi?

Asked

Viewed 315 times

1

I was having a lot of doubts about that. I searched several articles about it over the course of days, but in all of them I saw a flaw, most did not clearly show how to send a parameter or variable of the Delphi code to the Fastreport execution environment. Not even in the extensive documentation of the Fastreport component and in the forums of it I found something clearly, only after finding a good article next to the solution here: https://stackoverflow.com/questions/31813438/how-to-verify-that-a-file-exists-in-fastreport-4

Finally, using the method "trial and error" (rss) with the tip above, I ended up solving the question, and as I know that many are or end up having the same problem, I will post the solution I was able to do and who knows how to collaborate with others who have had similar doubts:

in my project, a Delphi application for Web, using Intraweb components, in the Asyncclick event of the "PRINT" button I export the report in PDF format:

procedure TF_produtos.bt_imprimirAsyncClick(Sender: TObject; EventParams: TStringList);
var
  objExportfilter : TfrxCustomExportFilter;
begin
  objExportfilter := TfrxCustomExportFilter(frx_PDF);
  objExportfilter.ShowDialog := False;
  objExportfilter.FileName := GetCurrentDir + '\wwwroot\impressos\frx_produtos.pdf';

//passando como parâmetro a variável 'img_path' o caminho da aplicação e o diretório das imagens salvas..
  frx_produtos.Variables['img_path'] := frx_produtos.GetApplicationFolder+'wwwroot\produtos\'; 

  frx_produtos.PrepareReport(True);
  frx_produtos.Export(objExportfilter);
  WebApplication.CallBackResponse.AddJavaScriptToExecute('window.open("/impressos/frx_produtos.pdf");');
end; 

and here in the Fastreport design, in the Masterdata1 band’s Onbeforeprint event I included these lines where I retrieve the information passed in img_path and the name of the image file to the img_product component that will be inserted in the printed report.

procedure MasterData1OnBeforePrint(Sender: TfrxComponent);
var
  arquivo: string;                                                             
begin
  arquivo := report.Variables['img_path']+<frx_dbdataset."IMAGEM">;                                                                            
  img_produto.Picture.LoadFromFile(arquivo);
end; 

result (images):

relatório com imagens ajustando o FastReport em tempo de desing do relatório referenciando o caminho "img_path" das imagens salvas antes de carregar o relatório

Guys, this is the way I found to solve the problem, but I hope that (according to the rules here) the Stack-Overflow staff will allow me to share and help others who have had the same doubt and who as I have not found complete, clear or objective answers. (I did as requested here, described the question, pasted a part of the code (the most relevant excerpts) and I believe that there is no other criteria that is missing, rss

Well, for now it is just, who wants to comment or suggest something, feel free, rss. Hugs, Hezekiah =O)

  • Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativations worth understanding What is the Stack Overflow and read the Stack Overflow Survival Guide (summarized) in Portuguese.

  • Good afternoon. Everything straight?? Guy never really went through this problem with FAST REPORT, but in case I pass , I already know how to solve.. Thanks for posting a solution. Hugs :)

  • Thank you Ricardo! The fact is that when I researched before, I was not finding any clear example, no example explained how to define and pass the code side parameter in Delphi, I couldn’t even find in the full Fast-Report documentation example (which makes many questions go unanswered, rss) and I ended up having to draw alone in the old method "trial-error-and-hits" until it works out, kkk but to publish the tip, I had to submit as if it were a question (site rules) the only way to do it here in Stack, rsrs

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.