Multi-informatica
 

 

 

Products

 

Resources

 

 

 

Using FastReport in IntraWeb. 20/6/2007

FastReport is a powerfull and popular component library to create reports.

If you are an IntraWeb programmer, then maybe you think on obtaining pretty pdf reports, by reusing old desktop reports.

Really it is very easy, but if you don’t use some tricks, then it will be difficult for you.

Let’s go to see how to create a normal pdf report in a normal Delphi deskop application:

 

var pdf: TfrxPDFExport; frreport: TfrxReport;

procedure CrearReport (const nam,resul:String);
begin
frReport.LoadFromFile(nam);
pdf.ShowDialog:=false; //Turn off dialog
pdf.FileName:=resul; frReport.PrepareReport(true);
frReport.export (pdf)
end;

This procedure has as parameter; nam ( which is the template name) and resul which is the pdf result file name.

This procedure (or similar), works fine in a desktop program. But if we want to do the same in an IntraWeb program, trying to create a report as a response to a request command form on a Web page,it is possible that it does not work initially.

What happened? In IntraWeb, the response to the commands was processed in a thread. It is well known the problem that when you want to create a form in a thread process (not in the main application thread) the forms can be inconsistent.

FastReport needs to create some forms (but invisible ones) to create the reports. If we use some similar code to code 1, our application will crash when we intent to create the report.

What is the solution? We will generate a new thread used to synchronize the report creation.

 

type
TIwFastResport = CLASS(TThread)

protected
procedure Execute; override;
public
na,resu:string;
constructor Create (const nas,resus:string);
procedure crear;
end; constructor TIwFastResport.Create (const nas,resus:string);
begin
inherited create (true);
freeonterminate:=false;
na:=nas;
resu:=resus;
end; procedure TIwFastResport.Execute; begin
synchronize (crear);
end; procedure TIwFastResport.crear;
begin
CrearReport (na,resu) end;

 



How to use the component ?

 

procedure TFormSample.ExportGen_( na:string; resu:string);
var th:TIwFastResport;
begin
th:=TIwFastResport.create(na,resu);
th.resume;
th.WaitFor;
th.Free;
WebApplication.SendFile(resu,True , 'application/binary', '');
end;

 

 

 

 

 

 
   

 

 

 

Teléfono: 978-610539 - Fax: 978-610861 -Trav.Agustina Aragón 1,1e 44002 Teruel ( España ).webmaster

Copyright © 1997-2004 , [Multi-Informatica Teruel, S.L].La información contenida en este documento está sujeta a modificaciones sin previo aviso. Otros productos u organizaciones mencionadas aquí son marcas comerciales o marcas registradas propiedad de sus respectivas organizaciones o propietarios.

  Zapatec