Mega Code Archive

 
Categories / Delphi / Forms
 

How to make reports in RTF format

Title: How to make reports in RTF format Question: How to make reports as nice as MS Word document? What if I wants that my reports were editable? How to make reports in RTF format? Answer: Using QR, I have tired to click on a form in attempts to get perfect reports. In this case I thought that it is a good idea to make report templates in Microsoft Word and get result in RTF format. Reports in RTF format is editable. Also don't worry about printing from your application, because this for you will do Word or any other editor, which you use.This idea realizes in EK RTF report component for Delphi. Let me show you in details how to make reports, using EK RTF report component. First of all you need a report template in RTF format. You may create a pattern of report by any available editor facilities, using font formatting, justification, colour, tables and other ways of formatting. To insert fields or variables from database in your report, use controlling words - they must be comprised between symbols "\" (back slash), for instance: \date\ or \Query1:CustNo\ Variable, which must be inserted in report will be assigned in VarList property in format variablename=value. For instance: if in the list VarList is kept a line name=John Smith, in the pattern of report must be a field \name\. You may insert in the report all records from table or query. For this in the editor (in Word or other) create a scan block with table. Use keywords \Scan(datasetname)\ and \endscan\. Type a name of fields to be inserted in the report in cells of the table. For example:Datasets are identified by name or by means of char a-z in that order, in which they were sent in Execute method. You may insert all records of dataset in the document in any free form, not only as table. Inside cycle scan-endscan can be located block of text of any form with names of data fields and variables, for example: \Scan(Query1)\Order number is \Query1:OrderNo\ Order sum is \Query1:OrderSum\\Endscan\ Lines with words "scan", "endscan" are excluded from the result document. However, if in step of designing a report you want to see as will look a result, you may set an attribute "hidden font" for words "scan", "endscan". There is an example of master-detail report: Component TEkRTF is used In this example with properties: Lang=wdEnglishUS, Name=EkRTF, properties INFILE, OUTFILE filled rtf file names. DisableControls=False. The other properties are left without changing. There are used tables ORDERS, CUST, ITEMS from DBDEMOS database. In the table ITEMS MasterFields=OrderNo, MasterSource=OrdersSource. Tables are in data module named DM. Report template: Before the executing report an user chooses an order number in ORDERS table. Correspond record in the table becomes the current. The second table is inside SCAN-ENDSCAN block. This allows to insert all records from table ITEMS, which correspond OrderNo from table ORDERS. Code to generate a report: custno:=Dm.orders.fieldbyname('custno').AsInteger; Dm.cust.Locate('CustNo',custno,[]); EkRtf.ClearVars;EkRtf.ExecuteOpen([DM.Cust,DM.Orders,DM.Items], SW_SHOW); Result: EK RTF report component for Delphi home page Storing EK RTF report template in blob field