Title: FastReport 3 EE - New Level in Reporting
Question: FastReport 3 EE greatly increases reporting productivity. It brings reporting activity for Delphi programmer to a new level. Article describes using FastReport 3 EE in real projects focusing on intregrating to existing code and simplicty of a solution.
Answer:
1. Strong Roots
Those developers who used FastReport v. 2 in their work know about its advantages well: convenient intuitive interface, compact code, very high work speed, availability of the Pascal-like scripting language and the means of form designing, which enable to produce reports that are completely independent of the logic "interweaved" in the program text.
It is very important that FastReport is delivered in the source code. That is why it is compiled directly into executable files of the created projects and requires no external libraries or execution environment. It is natural that the source code availability allows to dwell on such advantages as the ability of learning its works buried mechanisms features on your own or, if necessarily, making alterations in order to enlarge/alter the functionality, fit it to the framework of the concrete project.
A rather reasonable Fast Reports Inc. pricing is of no small importance for developers: a low FastReport cost and absence of any royalties on report designer embedding into end-user applications are rather competitive.
Everything that in block allowed FastReport to come out on top as the tool for report building in Delphi environment. That is confirmed by the title "Product of the Year", which FastReport got in the popular edition for Delphi developers - Delphi Informant Magazine
But the second version of FastReport had some drawbacks. Unfortunately, some of them are rather essential:
the script language was somewhat "unpredictable". It was rather difficult to write anything required via it. Due to that fact developers often sacrificed the "independence" of the created report and realized its logic in Delphi;
the scripts were inconvenient to write, as they were bound up with concrete objects and placed in objects' properties. This peculiarity complicated the complex reports development and maintenance very much, because it was impossible to realize whole logic "at one place". Moreover, absence of such basic properties of any procedural language as a subprogram also influenced the FastReport work complexity;
certain claims were presented to report designer - it had no zoom mode, and the accepted system of units did not allow to position objects stiffly accurately during high resolution printing.
The mentioned disadvantages were, perhaps, the most essential. They were not so much fundamental to put a question of backing away from FastReport in favor of the competitors, but they guaranteed non-pleasant pastime, which can just be called shamanism.
2. FastReport 3 - It Was Awaited Just the Very Same as It Is
Developers waited for the FastReport third version patiently for a long time. And after its release they were not disappointed: it can be literally asserted that the Fast Reports Inc. team brought about all the mostly claimed and awaited alterations in the product.
Let us point out the more significant among them:
new approach to the work with scripts - it is, perhaps, the most significant alteration. First, Fast Script - a new engine, which supports the PascalScript, C++Script, BasicScript, JScript languages and gives an opportunity for connecting a new language, is developed by Fast Reports Inc. It is used for script execution. Second, all the report scripts are not "scattered" about objects; they are placed in one unit, like Delphi unit, which supports procedures and functions. Third, it is to be noted that FastScript is a very flexible and functional engine supporting structured exception handling, functions and other constructions of the present-day procedural languages. It can be used independently of FastReport. The FastScript success is confirmed by the quotation in the "Libraries" category from the Delphi Informant Magazine Readers Choice Awards 2004: "The big story in this category is that FastScript (FastReports) has come out of nowhere to take 19% and second place" ;
new designer - now report designer has acquired very sound and presentable appearance and not less sound and presentable features: new considered interface with convenient element arrangement, zooming in designer mode, availability of multy-level action canceling/repetition of, full WYSIWYG, dragndrop support, new system of units enabling accurate object planning on high resolution type-out, built-in script debug;
new pattern and prepared report saving format - XML. XML support gives interesting opportunities for automatic generation of report patterns and their editing in the text form;
new approach to data access: now data sources needed to be accessed must be announced via the TfrxDataSet component. That is, undoubtedly, the more reasonable approach than that one accepted in the ver. 2. , when data sources which are useless for a report, on the contrary, had to be excluded in a special way;
and at last, the most interesting innovation, which is the subject of consideration in the following article: now FastReport 3 has Enterprise-version. It differs from the Professional one by the built-in Web-server enabling to view reports in Web-brouser. It also contains means for client application development. They allow to query report data from web-server via the HTTP protocol and display them in the form of a general report.
If to characterize FastReport 3 as a whole, it occurs to be a rather successful product: anyone can scarcely assert that there are any innovations, which did not do it good. The only noticeable inconvenience is that the new version does not support a backward compatibility with the old one, though it possesses means for already made applications migration. In particular, unit names and FastReport 3 classes hierarchy do not contain names crossing with the previous version. That is why it can be installed and used together with FastReport 2. , in one an the same application as well. That allows to make migration successive and smooth.
The author of the following article can affirm on the basis of his own experience that the transition process to the new version flows rather smooth: after expediency evaluating it took one week to transit to the new version of FastReport application containing about 20 rather complicated reports (in some of them there were scripts containing more than 2500 code lines). Besides, the whole work was performed by one and the same developer and new version advantages enabled to fasten the work with a project. Consequently the project execution overage term was not disturbed and all work was finished in time.
3. FastReport 3 Client/Server - How it Works
3.1. Functioning Scheme
FastReport 3 Client/Server work may be introduced in the following way (fig. 1)
Fig. 1. Functioning Scheme
Let us examine the figure in detail. In fact FastReport Server represents a HTTP - server. And it can serve client queries from the local network as well as from the Internet like any other HTTP-server.
FastReport Server can serve several clients simultaneously. For this purpose on client appealing a session manager creates a particular type session with unique identifier in session heap (Session Heap) and handles the client query independently of other queries that are active at that time. The created session type depends on client query. Two different session types are supported: file session and report session.
FastReport Server work in the file session servicing mode is like any other HTTP-server work: if client queries a file, it is returned to the client. If the file is a HTML-document, this document is preliminarily handled by SSI-Processor supporting directives set which simplifies building of sites including large number of pages. Thus, presence of such a mode enables to use FastReport Server for building not complicated sites on the "all in one" principle without using other Web - servers .
The second FastReport Server work mode is the mode of report session servicing. This mode is a basic one because it is in this mode where report building and its returning to a client are performed. Let us observe it in detail.
First, a query in the form of a line with report indication comes from a client to the server. The line is parsed and when it is correct report session creation is performed.
The report session, in its turn, creates a current with TfrxReport class that, in fact, performs report building.
The built report is stored in the temporary directory with session identifier (number). And client query is retargeted to the file, which contains it.
Later client receives a file with report just in the same way as in the file-oriented session service mode.
Both browser and application on the FastReport 3 basis (the TfrxReportClient component) can act as a client during report session service. In the first case report is saved into a temporary session directory and is transferred to the client in the HTML format , in the last case in the .fr3 format native for FastReport 3. That helps to receive a report that does not differ from general reports received by FastReport 3 Professional in its characteristics and capabilities for viewing and type-out. By the way, FastReport developers provide users with qualitative type-out of reports that are built in HTML format which, as everybody knows, does not fit exact print much. This opportunity is realized due to the optional capability of report transformation into the PDF format before its typing-out.
In addition, FastReport Server enables to keep a register of server work and also to collect statistics of clients query service.
A separate block is server variables. Server variables is a list of variables global for the server of variables that contain automatically built by the server and updated during work variables. These variables enable to receive such information as server name and version, its continuous running time, ultimate quantity of sessions and reports that can be performed simultaneously.
Taking into account that fact that usually reports contain confidential data, FastReport Server supports a definite kit of means for data security provision.
First, it is user authentification realized as a general HTTP authentification. Authentification runs in the following way: in order to receive an access to the server a client must transfer data about user name and password in the query heading (in accordance with RFC 2068). If the client receives a message with 401 "Unauthorized" code , he must repeat a query with correct user name and a password. If in such a case browser is a client, it displays a standard dialogue box with query for the user's name and password.
Second, these are lists of accepted and denied IP-addresses. You can point out concrete IP-addresses, from which connection is accepted, or set the lists of accepted and denied IP-addresses simultaneously.
So, FastReport Server contains a set of means for building a completely all-sufficient site that can contain additional information apart from reports. Supported accident preventatives provide a sufficient level of data security. And different types of clients (general browser or application on the basis of FastReport 3 client part) enable to satisfy any queries on displaying, typing-out or exporting into other information formats.
3.2. Components
Let us examine components offered by FastReport Server for building applications via Client/Server technology . After FastReport Enterprise Edition installation they appear on the Delphi FastReport 3.0 Client/Server tab.
Icon
Name
Description of components and the most important properties
TfrxReportServer
This component represents a report server and HTTP server. Its Active property defines whether the server is available for clients queries servicing at the present situation or not, it is sufficient to assign true to this property to run the server.
AllowIP and DenyIP properties have the TStrings type and contain the list of IP-addresses accordingly allowed and denied for connecting to the server.
The PrintPDF property enables to type-out a HTML-report using PDF format ( if it is installed in true) or to use browser HTML-pages regular printing (false) . On typing - out with the PDF format usage it is necessary to have the software for this format displaying and printing installed in the client computer ( Adobe Acrobat Reader ). The Configuration property has the TfrxServerConfig type and is assigned to specify different server settings . In particular, it is possible to set a directory, where reports are stored. However, if reports are not stored in files, but, for example, in data base BLOB-fields, the OnGetReport event, which enables to return a report by its name, should be used.
TfrxServerConnection
The given component serves as an intermediate layer between the TfrxReportClient client component and the TfrxReportServer server component. This component is charged with adjusting of connection from client direction to the server. Several instances of TfrxReportClient can be bound up with one and the same TfrxServerConnection.
The Host and Port properties define address and port of the server, accordingly (address can be set in the form of IP-address or domain name).
The ProxyHost and ProxyPort properties define address and port of HTTP-proxy server accordingly.
The Login and Password properties accordingly define name and password used on autentification.
The Compression property defines information compaction necessity on passing between the server and a client. It is preferable to be installed in true for network traffic economy.
TfrxReportClient
The given client component serves for receiving report from the server. It provides with query formation for receiving a report with indication of a concrete designation of the required report and, if necessary, performs transferring of parameters for report building. It requires TfrxServerConnection for its functioning (link is set via the Connection property) .
In the ReportName property report name, which is to be received from the server, is set.
In the Variables property the report parameters, which will be used in its building, can be placed (of course, a report must provide parameters).
In the Errors property notifications about all the mistakes ever occurred in case of abortive report building will be placed.
TfrxHTTPClient
The given component can be used for receiving random files according to HTTP protocol. It is convenient in usage when created client application can call for additional data from the server in addition to report.
The Active property enables to perform a query - query execution is performed on conferring true to it.
Such properties as Host, Port, ProxyHost, ProxyPort (here the second and the third letters are at their right places) perform the same functions as in the TfrxServerConnection component.
The ClientFields and ServerFields properties contain query heading fields and the server answering heading fields accordingly.
So, in order to create a server application , which will serve clients, return reports in HTML format and native FastReport 3 format and transfer random files according to HTTP protocol , it is sufficient to use just one (!) component - TfrxReportServer .
To view reports in the HTML format and their typing - out either in HTML or in PDF formats it is sufficient to use any modern Web-browser .
If it is necessary to create a client application , which is to produce reports in native FastReport 3 format , it is sufficient to use two components - TfrxServerConnection for connecting to the server and TfrxReportClient for performing report building and receiving query . In the client attachment TfrxReportClient can be used just in the same way as the general TfrxReport component, because it is its successor .
The TfrxHTTPClient component is more likely a bonus presented by Fast Reports , Inc . developers to programmers , than a tool for doing sums, for which Fast Report is destined . In fact , TfrxHTTPClient is used inside in TfrxReportClient and its accessibility as a separate component , probably , will occur to be a rather serious help in building complex applications .
Unfortunately , client - server applications development via the current version of FastReport Enterprise Edition applies definite restrictions on reports, which can be used for these objectives .
First , it is impossible to use any buried script handlers inside FastReport dialogue forms on usage of dialogue forms in reports . This limitation is due to the method of dialogue form handling : they are automatically transformed into Web - forms and are deduced as general HTML - pages before report deducing. That is why general FastReport scripts cannot be fulfilled in them .
Second , it is impossible to use TfrxReportClient event handlers for realization of such capabilities as , for example , user functions because report is built on the server. And the TfrxReportClient component just sends inquiry for report building , transfers parameters and receives the already built report. But does not take part in direct process of report building .
Third, on designing of reports that will be performed on the server, it should be borne in mind that these reports will be performed in a multithreaded environment . T hat is why resource sharing problems should be taken into account . Particularly, special attention should be paid to isolation of report access to data. For example, you should refrain from usage of database access general components via the TfrxDataSet component .
Let us examine a concrete practical problem and its solution via FastReport Enterprise Edition.
4. Realization of the Client-Server Application in Practice
4.1. Task Description
Prehistory of the task is very vital and looks in like: at a certain enterprise there is a certain system of automation, which forms reports in FastReport by results of its work. Owners of such an enterprise located in another city would like to have an opportunity to see the given reports. However, they are not ready to pay for the certain distributed system development and support (i.e. roughly speaking, to increase project budget).
It is a rather typical task, which is usually solved just via creation of a distributed system supporting data replication. However, this is a rather expensive solution. It is especially unacceptable when the system develops itself and requires frequent modifications.
The alternative variant is creation of Web-server that provides report access. If developing tools which are in use do not provide for such functionality by standard, such a solution also may occur to be rather expensive both in development and in the subsequent maintenance.
The author of this article took part in developing of a rather unique solution of the task via FastReport 2.5 : there was created a software product, which enabled to build reports in automated operation, save them to file and transfer them to mail program for moving. All reports were completed in such a way that they contained variables receiving values either from form fields filled by a user or from scripts of application running in automatic mode. So, one and the same report could be either formed by a user in dialogue mode or by a program for automatic report building without operator participation.
This approach had the only essential drawback: rules for report parameters infill must be defined beforehand and realized via script, which can be prepared only by a qualified programmer (excluding inessential modifications of completed scripts which can be performed by an advanced user).
In spite of the fact that the created solution formally managed with the task, it was not sufficiently flexible and provided for definite effort for maintenance.
4.2. Task Solution
FastReport Enterprise Edition gives the best fit to this task solution as it enables to provide remote clients access to reports with minimum costs and at the same time exclude client software maintenance expenditures if Web-browser acts as a client. At the same time, as it was pointed out earlier, the migration from the 2. version passes rather softly.
So, let us define specific requirements for our solution: it is necessary to create a Web-site using FastReport Enterprise Edition, which enables to receive access to definite reports building by a remote user. Usual Web-browsers will act as clients. There should be granted an opportunity for report viewing, printing and, if necessary, saving in the MS Excel format for subsequent handling. As reports contain confidential information, it is necessary to provide access to their building only for approved users. And one more requirement: development simplicity and speed is one of the key factors urged to make the project cheaper as much as possible during the given solution development.
At the preparatory stage during the solution of the posed task it is required to perform reports preparation. First, they must be converted into the new FastReport 3 format (this can be performed via the report saving in .fr3 format function that appeared in FastReport 2.54). Second, reports need to be finished off taking into account restrictions pointed out earlier, which collide by the FastReport Enterprise Edition server architecture (taking into account free threading, absence of dialogue form script handlers, excluding of TfrxReport event handlers).
Then, let us create directories where reports, HTML-pages and registers are placed (it is recommended to place different types of files in different directories). Let them be directories with the names Reports, HTML, Logs, accordingly.
Then place the reports in the Reports directory, let them be Report1.fr3 and Report2.fr3.
If client knows names of the reports he wants to receive from the server, he can compose a query returning a specific report according to its name in the browser address bar (that can be performed if to compose a similar query: http://server_address/report=Report1.fr3 or http://server_sddress/result?report=Report1.fr3). However, it is likely to create a HTML-page, where you can select a required report and go to it via a link. To perform that let us create a HTML-document with the index.html name in the HTML directory:
Welcome to the report server of X-corporation! The list of available reports: Report 1 Report 2
Then let us realize a required functionality in Delphi (we used Delphi 2005 and FastReport 3 Enterprise Edition version 3.11 for this article). As in the given case it is a question of existing project modernization, we add the TfrxReportServer component from the FastReport 3.0 Client/Server tab to it.
Set the following values for component properties (please note, that the FastReport EE 3.11 version was used for writing the given article. Probably, the setting of other properties will be required for other versions. For example, Logging property in the version to the 3.09 was false by default. And beginning with the 3.10 it is true):
// paths to directories for keeping registers, and reports and HTML-pages storing
Configuration.LogPath := .\Logs\
Configuration.ReportPath := .\Reports\
Configuration.RootPath := .\HTML\
// Authentification data
Configuration.Login := BigBoss
Configuration.Password := SecretPass
Let us leave the rest of properties with default values. On entering data for authentification, pay attention to the fact that not only password but also user name depend on symbol register.
To make the created server function it is sufficient to assign true value to the Active property. The server begins to run even on the given operation performing in design-time.
Let us start Web-browser and enter the http://localhost/ address. There appears a dialogue-box with authentification data query (Remember, we using BigBoss for user name and SecretPass for password). After their entering (do not forget about dependence of user name and password on register), you can see a page of the following content:
On selecting of any offered reports a new browser page opens and you receive a built report. For example, on selecting Report 1 you receive the following report (in the given article reports from the FastReport demo project, which is included into a standard delivery, are used):
On clicking on the Print button the report is converted into PDF format. It will be displayed in a printing-friendly mode with the installed application for such format viewing:
The task is practically solved. There remains one more small touch: in the solution requirements the possibility of report transference into MS Excel format, if necessarily, was pointed out.
It is very easy to perform that. It is sufficient to form a correct query to the server. To produce a Report1.fr3 report in the XLS format it is necessary to send the following query to the server: http://server_address/report=Report1.fr3&format=XlS.
Modify the HTML-document according this requirement:
Welcome to the report server of X-corporation! The list of available reports: Report 1 (Excel Format) Report 2 (Excel Format)
Now a page with reports selection looks like:
And on building the Report 2 report in the MS Excel format we receive a nice calendar. Instead of it there, of course, can be any figures delivered to Big Boss in the form suitable for editing and subsequent analysis using electronic worksheets:
Well, taking into account the posed requirements, our task may be regarded as solved.
In the given article the client application creation via the FastReport Enterprise Edition client components is not examined, as their usage was not required for the posed task solving. However, there is nothing complicated in their usage: client application development does not differ at all from the general application development on FastReport basis with the TfrxReport component usage. But there is only one exception: a bundle of two components should be used. They are TfrxServerConnection and TrxfReportClient. If client connection is setup right, then working with TrxfReportClient creates perfect illusion of a general local report building with the only difference that, in fact, a report cam be built on the server placed at the other end of the world.
5. Summary
So, there remain only several words to write as a summary. Here it would be too long to describe the advantages, which FastReport Enterprise Edition offers for developers. But the author of the article considers everything written above speaking for itself.
As a matter of fact, one of the requirements for the project realization examined in the article was the following: development simplicity and speed is one of the key factors urged to make the project cheaper as much as possible during the given solution development . Probably, nobody has any doubt about the fact that the posed task solution occurred to be really easy.
Has anyone paid attention to the fact that the posed task solution was performed without writing at least one code line in Delphi? Everything we did was creating HTML-page text, placing components on the form (one component!) and setting properties to them. But we really did not write a code in Delphi. The author of the article paid his attention to this fact only at the end of it
Probably, anyone has any doubt on the practical value of FastReport Enterprise Edition? May be But as for me, I have not any!
Example code (Delphi 2005) (20,5 Kb)