Report Builder for Delphi: Design Reports Visually or in Code

sgcReports is a report builder for Delphi and C++ Builder: your users design reports visually, and your code builds them with the fluent TsgcReportBuilder class.

VCL, FireMonkey and web designers
Reports built in code
Bands, groups and master detail
Export to PDF, Excel and CSV

See pricing →

Delphi report preview with a finished sales by region and month report, KPI boxes and a stacked revenue chart, Export PDF and Export XLSX buttons, built with sgcReports in the Altamira ERP demo

Two Ways to Build a Report in Delphi

A report is a model of pages, bands, items, styles and data sources. The designer and the code both edit that model, and a JSON definition stores it.

Your users design reports visually in the VCL, FireMonkey or web report designer, and your code builds them with the fluent TsgcReportBuilder class. Both produce the same report model, with bands, groups, master detail and expressions, which you preview, print or export to PDF, Excel, CSV and more, on the desktop or in a service with no window.

Visual report designer

Drop a TsgcVCLReportDesigner or a TsgcFMXReportDesigner on a form, or serve TsgcReportHTMLDesigner in the browser. Users drag fields onto bands, set properties in an inspector and switch to a live preview. Registered

Design reports visually →

Reports as code

TsgcReportBuilder describes styles, pages, bands and items as one fluent chain. The report compiles, diffs and refactors with the rest of your project, and works from Delphi 7, with no anonymous methods required.

Build reports in code →

JSON definitions

Save a report with sgcReportSaveToJSONFile and load it at run time, so a layout can live in a database or a customer folder and change without a new build. The designers open and save the same files.

About JSON definitions →

Design Reports Visually in VCL, FireMonkey and the Browser

An end-user report designer your users run inside your application, and the same designer at design time in the IDE.

The VCL report designer of sgcReports with a delivery note open, the band outline, the design surface and the property inspector

Report designer Registered only

A report designer your users can run

TsgcVCLReportDesigner is a panel with a toolbar, the Toolbox, Outline and Data tabs, a design surface with rulers, a property inspector, and Design and Preview tabs. Drop it on a form, assign Engine, add the data sources, and your users edit the report, save it as a JSON definition and preview it with live data. TsgcFMXReportDesigner is the FireMonkey twin, built over the same designer units.

  • Toolbar with New, Open, Import, Save, Undo, Redo, alignment, distribution and zoom
  • Drag an item from the Toolbox or a field from the Data tree onto a band: text, rich text, image, line, shape, barcode, subreport, page break, crosstab and table
  • Editors for the report parameters, tables and the report script
  • The Preview tab prepares the report with the data of the engine
  • At design time, right click a TsgcReportEngine in the IDE and choose Design report… to edit its report with the same designer
Read the help topic

Connect the designer to the engine and the data sources when the form is created, and load the last saved layout:

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  sgcDesigner.Engine := sgcEngine;
  sgcDesigner.AddDataSource(sgcOrders);
  if FileExists('orders.json') then
    sgcDesigner.LoadFromFile('orders.json')
  else
    sgcDesigner.NewReport;
end;

procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if sgcDesigner.Modified then
    sgcDesigner.SaveToFile('orders.json');
end;

To edit a report from a menu without a dedicated form, sgcShowReportDesigner (VCL) or sgcShowReportDesignerFMX (FireMonkey, Windows and macOS) shows the designer modally with OK and Cancel buttons, and restores the report when the user cancels:

procedure TfrmMain.mnuEditReportClick(Sender: TObject);
begin
  if sgcShowReportDesigner(sgcEngine) then
    sgcReportSaveToJSONFile(sgcEngine.Report, 'orders.json');
end;

FireMonkey designer

TsgcFMXReportDesigner (Delphi XE6 and later) has the same toolbar, trees, surface, inspector and preview tab, hosting a TsgcReportPreviewFMX. ToolbarButtonSize makes the buttons easy to tap on a touch screen. The modal form and the file dialogs are available on Windows and macOS.

Web report designer

TsgcReportHTMLDesigner edits the JSON definition in the browser with a band canvas, a property inspector and a live preview, served by the same HTTP endpoint as the finished report. It needs sgcWebSockets Professional or higher and sgcHTML. Leave DesignerEnabled off on production endpoints and put it behind your own authentication.

About the web designer →

.NET designers

sgcReports for .NET includes end-user designers for WinForms, WPF and Avalonia, the counterparts of TsgcVCLReportDesigner, with the same toolbar, trees, inspector and preview. They load and save JSON definitions too.

Build Reports in Code with TsgcReportBuilder

A grouped sales report over any TDataSet: a header per region, a line per sale, a subtotal per region and a page footer, saved as PDF and Excel.

uses
  Classes, SysUtils, DB,
  sgcReports_Types, sgcReports_Model, sgcReports_Data, sgcReports_Fluent;

const
  CS_TOTAL = '[FormatFloat(''#,0.00'', Sum(Sales.Amount))]';

procedure ExportSalesReport(aSales: TDataSet; const aFolder: string);
var
  oSales: TsgcReportDataSetSource;
  oBuilder: TsgcReportBuilder;
begin
  oSales := TsgcReportDataSetSource.Create(nil);
  oBuilder := TsgcReportBuilder.Create;
  try
    // any TDataSet: FireDAC, TClientDataSet, dbExpress...
    oSales.SourceName := 'Sales';
    oSales.DataSet := aSales;
    oBuilder.Title('Sales by region').Units(ruMillimeters)
      .Style('Base').Font('Arial', 10).EndStyle
      .Style('Group').Font('Arial', 11).Bold.BackColor($EEEEEE).EndStyle
      .Page.Paper(rpsA4).Margins(15)
      .GroupHeader('Sales.Region', 9).Style('Group')
      .Text('Region: [Sales.Region]', 0, 1, 180, 7).TagRole(rtrHeading2).EndBand
      .MasterData('Sales', 6).Style('Base')
      .Text('[Sales.Customer]', 2, 0, 120, 6)
      .Text('[Sales.Amount]', 130, 0, 50, 6).AlignRight.Format('#,0.00').EndBand
      .GroupFooter(9).Style('Base')
      .Text('Region total ' + CS_TOTAL, 80, 1, 100, 6).AlignRight.Bold.EndBand
      .PageFooter(8).Style('Base')
      .Text('Page [Page] of [TotalPages]', 0, 1, 180, 6).AlignCenter.EndBand
      .EndPage.Data(oSales);
    oBuilder.SaveToPDF(IncludeTrailingPathDelimiter(aFolder) + 'sales.pdf');
    oBuilder.SaveToXLSX(IncludeTrailingPathDelimiter(aFolder) + 'sales.xlsx');
  finally
    oBuilder.Free;
    oSales.Free;
  end;
end;

Read the TsgcReportBuilder help topic

Bands, Groups and Expressions

A real banded layout, so business reports such as sales by region or invoices by customer need no workarounds.

A grouped Delphi report with a header per group, subtotals and page numbers

Bands and groups

Report title, headers, data, footers and summary

A report has report title, page header, group header, data, group footer, page footer and summary bands, plus column headers and footers. A group breaks when its expression changes, prints its own totals and can start a new page or repeat its header on every page. Subreports let one page include the layout of another.

  • GroupExpression on a group header band, and nested groups for two or more levels
  • StartNewPage, RepeatOnEveryPage and KeepTogether control the page flow
  • PrintOnFirstPage and PrintOnLastPage decide where page bands appear
  • Tables, crosstabs, rich text, barcodes, check boxes and SVG pictures as report items
Read the help topic

Expressions

Totals, formats and conditions in brackets

Any text item holds expressions in brackets, evaluated by the engine for every row, so a footer total always matches the lines printed above it. There are 68 functions and 10 aggregates, including date arithmetic, padding and formatting, ToWords in 12 languages, conditional aggregates and running values that restart with every group.

'[Sum(Lines.Qty * Lines.Price)]'
'[FormatDateTime(''dd/mm/yyyy'', Invoices.Date)]'
'Page [Page] of [TotalPages]'
  • Sum, FormatFloat, FormatDateTime, Upper, Round, IsNull, SumIf, CountIf, RunningSum and Previous
  • OnGetVariable supplies your own variables at run time
  • Highlights apply a style when a condition is true, for example negative amounts in red, with no script
Read the help topic

Data from TDataSet, Master Detail Included

The report reads your data where it already lives: a query, a JSON document or your own objects.

An invoice report built from master and detail datasets, with its lines, totals and a QR code

Master detail

Invoices and their lines from two datasets

TsgcReportDataSetSource reads any TDataSet, such as TClientDataSet, FireDAC or dbExpress. A detail source links to its master by key fields, so each invoice prints its own lines, and the group footer sums them. Left unopened, the dataset is opened and closed around the run; already open, its state and position are restored afterward.

  • MasterSource, MasterFields and DetailFields link the sources
  • TsgcReportJSONSource reads a JSON string or file, RecordsPath picks the array
  • TsgcReportEventSource pulls rows from your code through OnFirst, OnNext and OnGetValue
  • Report parameters are given to the query parameters of the same name before the run
Read the help topic
srcInvoices.SourceName := 'Invoices';
srcInvoices.DataSet := cdsInvoices;
srcLines.SourceName := 'Lines';
srcLines.DataSet := cdsLines;
srcLines.MasterSource := srcInvoices;
srcLines.MasterFields := 'Number';
srcLines.DetailFields := 'Invoice';
sgcEngine.AddDataSource(srcInvoices);
sgcEngine.AddDataSource(srcLines);

Export a Delphi Report to PDF, Excel, CSV and More

The engine prepares the pages once, and every export works from the same prepared result, so the numbers are identical in every file.

The same report exported to PDF, an Excel workbook and a CSV file

Output formats

One prepared report, every format

The PDF export writes tagged PDF/UA-1 by default, and PDF/A-3 for long term archives. XLSX output keeps numbers as numbers, so the spreadsheet sums them without cleanup. Every export can write to a file or to a stream.

  • Every edition: PDF, PDF/A, PDF/UA, XLSX, CSV, PNG, HTML, ODS, SVG and plain text
  • Registered edition: DOCX, ODT and RTF
  • PDF output through the sgcPDF Delphi PDF library, with embedded fonts and vector barcodes
Read the help topic
FPages := sgcEngine.Prepare;
try
  pdfExport.SaveToFile(FPages, OutputFolder + 'orders.pdf');
  xlsxExport.SaveToFile(FPages, OutputFolder + 'orders.xlsx');
  csvExport.SaveToFile(FPages, OutputFolder + 'orders.csv');
  imageExport.SaveToFiles(FPages, OutputFolder + 'orders_%d.png');
finally
  FPages.Free;
end;

Preview and Print Reports in VCL and FireMonkey

Users page through the report before they print or save it, with the same rendering as the PDF.

The sgcReports preview window in a Delphi application with an invoice page and a QR code

Preview and printing

A preview control with print and export

TsgcReportPreviewVCL shows the prepared pages with navigation, zoom and fit modes, prints them and saves them to PDF. The previews find text with the matches highlighted, show page thumbnails and export to PDF, Excel, CSV, PNG, HTML, Word, ODT, ODS, RTF, SVG and plain text from an Export menu. TsgcReportPreviewFMX is the FireMonkey preview on Windows, macOS, iOS and Android.

  • FirstPage, NextPage, PriorPage and LastPage, ZoomIn, ZoomOut, FitWidth and FitPage
  • Typed report parameters with a prompt before the report is prepared
  • Page and record counts while a long report is prepared, with a Cancel button
Read the help topic
procedure TfrmMain.btnPreviewClick(Sender: TObject);
begin
  sgcPreview.Engine := sgcEngine;
  sgcPreview.Prepare;
end;

procedure TfrmMain.btnPrintClick(Sender: TObject);
begin
  sgcPreview.Print('Sales by region');
end;

Generate Reports Headless in Services and Daemons

Nightly statements, invoices after checkout and exports behind an API run on a server with no window.

No VCL, no DLL, no printer driver

The sgcReports core has no VCL or FireMonkey dependency and needs no external DLL or printer driver. TsgcReportEngine prepares reports with no window, in a Windows service or a Linux64 daemon.

One engine per thread

Each worker creates its own report, engine, data sources and exports, while a read only TsgcReportFontManager serves every thread. sgcReportsConfigureForServer tunes the memory manager for many threads on Windows.

Layouts from the designer

A definition saved by the designer is a normal JSON file, so a server loads it with sgcReportLoadFromJSONFile and runs it headless. The ReportLinuxDaemon demo watches a jobs folder and renders PDF, XLSX, CSV or PNG with 4 worker threads.

Linux daemon help topic →

Bring Your Existing Report Templates

An application that moves to sgcReports usually has many reports already. Convert them instead of drawing them again.

Report import Registered only

Import ReportBuilder .rtm templates and QuickReport forms

TsgcReportImporter converts QuickReport forms (.dfm with a TQuickRep) and ReportBuilder templates (.rtm), as text or binary, into report definitions and lists every object, property, expression and script it could not map. The VCL, FireMonkey, WinForms, WPF and Avalonia designers have an Import command. You review the list, add the data sources, fix the rest in the designer and save the result as a JSON definition.

  • The format is detected by itself, so one call handles both kinds of file
  • A ReportBuilder pipeline or a QuickReport data set becomes a data source name; DataSourceMap renames it to your own source
  • ImportResult holds the result of the last import, and the designers show the issues in a window
Read the help topic
oReport := TsgcReport.Create(nil);
oImporter := TsgcReportImporter.Create;
try
  // the old pipeline Orders is the data source Sales here
  oImporter.DataSourceMap.Values['Orders'] := 'Sales';
  try
    oImporter.ImportFromFile(oReport, 'orders.rtm');
    sgcReportSaveToJSONFile(oReport, 'orders.json');
  except
    on E: ESgcReportImportError do
      WriteLn('Not imported: ', E.Message);
  end;
finally
  oImporter.Free;
  oReport.Free;
end;

Moving a whole application? The QuickReport migration kit maps bands and controls to their sgcReports twins with numbered steps.

Delphi Versions, Platforms and Editions

TargetWhat runsPlatforms
Delphi 7 to 13Report model, expressions, data, layout, engine, fluent builder and exportsWindows, Linux64, macOS, iOS and Android
C++ Builder 2007 to 13The same classesGenerated .hpp headers and static libraries
VCL designer and previewTsgcVCLReportDesigner, TsgcReportPreviewVCLWindows
FireMonkey designer and previewTsgcFMXReportDesigner (Delphi XE6 and later), TsgcReportPreviewFMXPreview on Windows, macOS, iOS and Android

sgcReports is sold on its own from €199 per developer, with full source code and 1 year of updates, and it is included in sgcUI Enterprise and the All-Access bundle. It writes PDF through sgcPDF, which is required in every configuration. The end-user designers, the report import, DOCX, ODT and RTF export and the web designer are in the Registered edition; the trial has every feature unlocked.

See pricing Feature matrix

Report Builder Questions

Bind your data with a TsgcReportDataSetSource over a TDataSet, describe the bands with TsgcReportBuilder and call SaveToPDF, as in the code sample above. If you prefer to draw the layout, drop a TsgcReport, a TsgcReportEngine and a TsgcVCLReportDesigner on a form, design the report and save it as a JSON definition. Both ways produce the same report model.

Yes, in the Registered edition. TsgcVCLReportDesigner and TsgcFMXReportDesigner are end-user designers you embed in your forms, and sgcShowReportDesigner opens one modally from a menu. For web applications, TsgcReportHTMLDesigner runs in the browser. Every designer saves JSON definitions that load anywhere in sgcReports.

Yes, in the Registered edition. TsgcReportImporter converts ReportBuilder templates (.rtm), as text or binary, and QuickReport forms (.dfm with a TQuickRep) into report definitions, and lists every object, property, expression and script it could not map. The designers have an Import command that does the same. See Bring your existing report templates.

Yes. SaveToPDF and SaveToXLSX on the builder, or TsgcReportPDFExport and TsgcReportXLSXExport on prepared pages, write tagged PDF/UA-1 (PDF/A-3 on request) and Excel workbooks that keep numbers as numbers. CSV, PNG, HTML, ODS, SVG and plain text are in every edition, and DOCX, ODT and RTF in the Registered edition.

Assign the engine to a TsgcReportPreviewVCL and call Prepare. The preview pages, zooms, finds text and exports, and Print prints the shown document. FireMonkey applications use TsgcReportPreviewFMX on Windows, macOS, iOS and Android.

Yes. The core has no VCL or FireMonkey dependency and no external DLL, so TsgcReportEngine and the exports run in Windows services and Linux64 daemons, with one engine per thread. The ReportLinuxDaemon demo renders jobs from a folder with 4 worker threads.

Delphi 7 to 13 and C++ Builder 2007 to 13. TsgcReportBuilder is a plain class that works on Delphi 7, with no anonymous methods required. The FireMonkey designer needs Delphi XE6 or later. The same classes are available for .NET.

Yes, always. sgcReports writes PDF and draws barcodes with the sgcPDF engine, and the previews draw through the sgcPDF viewer control. sgcUI Enterprise includes both.

Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Try the Report Builder

The sgcUI trial includes sgcReports, its designers and sgcPDF, with every feature unlocked.