• Blog
  • Mastering FastReport in Delphi: Dynamic File Reporting and Visualization

Mastering FastReport in Delphi: Dynamic File Reporting and Visualization

Effortlessly create dynamic reports and explore Delphi’s FastReport capabilities.

Publish date:
Discover more of what matters to you

Whenever we think we finally have enough storage space, manufacturers introduce something new—and, of course, more expensive.

If you haven’t realized it yet from the title, this article will focus on FastReport, one of Delphi’s most remarkable reporting libraries. If the title didn’t give it away, take another look and consider buying yourself a copy of FastReport while you’re at it.

Setting Up the Application

We’ll begin by creating a new VCL application, setting up the main form and primary DataModule, and adhering to standard best practices.

For navigation, we’ll use the free components from Mustangpeak – VirtualShellTools, which, in turn, are based on VirtualTreeView.

To make things more engaging—and to avoid the hassle of manually installing components—we’ll create everything dynamically at runtime. This approach only requires adding the appropriate paths to VirtualTreeView and VirtualShellTools.

To get started, we’ll add a Tree: TVirtualExplorerTreeview field to the definition of our main form. Next, we’ll define the TreeChange procedure, which will handle navigation through the tree structure.

123456789101112131415
TMainForm = class(TForm)
Preview: TfrxPreview;
pnOptions: TPanel;
Splitter: Splinters;
StatusBar: StateBar;
pnTree: TPanel;
cbFileType: TCheckBox;
CheckBox1: TCheckBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
procedure TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
public
Tree: TVirtualExplorerTreeview;
end;

Tree Creation on FormCreate

On FormCreate, let’s prescribe the creation of a tree:

1234567891011121314151617181920
Tree := TVirtualExplorerTreeview.Create(Self);
with Tree do
begin
Font.Size := 10;
DefaultNodeHeight := Canvas.TextHeight('Aq') + 6;
AlignWithMargins := True;
Align := alClient;
BorderStyle := bsNone;
CommandChild := bkNone;
ButtonStyle := bsTriangle;
TreeOptions.PaintOptions := [toShowButtons, toUseExplorerTheme, toThemeAware];
TreeOptions.SelectionOptions := TreeOptions.SelectionOptions + [toFullRowSelect];
TreeOptions.VETFolderOptions := TreeOptions.VETFolderOptions – [toThreadedExpandMark];
TreeOptions.VETShellOptions := TreeOptions.VETShellOptions – [toDragDrop];
TreeOptions.MiscOptions := TreeOptions.MiscOptions – [toAcceptOLEDrop];
OnChange := TreeChange;
Parent := pnTree;
Active := True;
end;

I won’t elaborate on all the assignments here, as they seem quite straightforward to me. If you have any questions, feel free to leave a comment—I’ll make sure to respond.

Now that the tree is set up, let’s dive in and get started:

Setting Up the Report

On the left, we have a file tree, and on the right, we have the TfrxPreview component for displaying the report. Now, let’s focus on the report itself. We created it in a separate Data module so that the work with the report remains logically separated from the navigation form. This is important because when something can be divided into two modules, it’s better to do so from the beginning. This approach helps us avoid unnecessary dependencies, creates a more convenient file structure for development, and allows us to organize the work more efficiently. So, let’s proceed with the setup and make the magic happen!

Putting in the TfrxReport component and a couple of TfrxUserDatasets

Double-click on FRX and create the following structure:

ReportTitle – displays the name of the report. Here, we will show details about the disk we are working with. Below, in the ChildBand, we will present information about the free and occupied space, along with a diagram visually illustrating this data.

Next, the Header will display the current directory’s name, followed by the MasterData section, which includes file details such as icon, file type, size, and name. Since this information doesn’t occupy much space, we’ll divide the MasterData into three columns (using the Columns property) and adjust the column width to fit neatly on the page. I settled on 6.30 for the column size.

Note that we don’t create any predefined fields for our UserDatasets. Instead, when accessing them (for example, [dsDrive.”Capacity”]), we assign names dynamically as needed. To ensure everything works seamlessly, we need to set up a couple of events. The OnGetValue event is where we will return the disk data:

12345678910111213
procedure TDataFR.dsDriveGetValue(const VarName: string; var Value: Variant);
var
Bytes: Int64;
begin
case IndexText(VarName, ['FREE', 'USED', 'CAPACITY']) of
0 {FREE}: Bytes := FDriveInfo.Free;
1 {USED}: Bytes := FDriveInfo.Used;
2 {CAPACITY}: Bytes := FDriveInfo.Capacity;
else
Exit;
end;
Value := SizeToStr(Bytes);
end;

The description you’ve provided refers to two key events in the FastReport framework:

  1. OnIsBlobField: This event indicates that a field (in this case, the PICTURE field) is a BLOB (Binary Large Object). It essentially means that the field contains binary data, such as an image or other non-text data.
  2. OnGetBlobValue: This event is where the actual image (or other binary data) is created. In this context, it is used to generate a diagram, which is then converted into a bitmap and passed to FastReport using a TMemoryStream. This allows FastReport to display the image within the report.

By using these two events, you can dynamically handle and display images or other complex data types in your reports, creating a visually appealing and functional output. The result is a report where the data and images are seamlessly integrated.

Gain full access to our guide on handling files, adding subreports, and setting up reports in FastReport. Learn how to streamline workflows using OnFirst, OnCheckEOF, and OnNext events, optimize ChildBands and Subreports, and configure TfrxReport components efficiently. Fill in the form.

Get access to the article by completing your name and e-mail address.

This field is required
This field is required Invalid email address Invalid business email address
By submitting data, I agree to the Privacy Policy
Tags
Get in touch
Our benefits
  • 17+ years of expertise in legacy software modernization
  • AI Migration Tool:
    faster timelines, lower costs, better accuracy (99.9%)
  • Accelerate release cycles by 30–50% compared to manual migration
  • 1–2 business day turnaround for detailed estimates
  • Trusted by clients across the USA, UK, Germany, and other European countries
Review
Thanks to Softacom's efforts, the solutions they delivered are already in use and have increased revenue streams.
  • Niels Thomassen
  • Microcom A/S
This field is required
This field is required Invalid email address Invalid business email address
This field is required
By submitting data, I agree to the Privacy Policy
We’ll reply within 24 hours — no sales talk, no spam