Delphi form

This example uses Northwind MS Access database. The report displays data from a table Customers in an output document.

There is TADOTable component on a Form1, which is connected to the database table. EkRTF1 is TEkRTF component. The report template is saved in QuickStart_template.rtf file. The name of the report template is set to EkRTF1.InFile property before executing.


Report template

The report template contains fields enclosed within the \\ chars. The first is built-in function now(), which shows current date and time. The next is report variable database_name. Its value set before making report from template. Fields \Scan(Customers)\ \EndScan\ are EK RTF commands. Three fields inside the table are links to Customers table fields.

Code to generate the report

procedure TForm1.Button2Click(Sender: TObject);
begin
  (* check report template file *)
  if not FileExists(EkRTF1.InFile) then
  begin
    if RTFDialog.Execute then begin
       EkRTF1.InFile := RTFDialog.FileName;
    end else exit;
  end;
  (* create report *)
  EkRTF1.ClearVars;
  EkRTF1.CreateVar('database_name',dbname);
  EkRtf1.ExecuteOpen([Customers],SW_SHOW);
end;


Result