logo
small logo
  • Products
  • Buy
  • Support
  • About
  • Customer panel Support
    • en
    • de
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Using resources for storing FastReport reports
  • Turn database data into a document in Delphi / Lazarus / C++ Builder

    February 3, 2021

    How to make a mush of data into an informative report? Oracle DB, MySQL, Microsoft SQL

    read more
  • How to create one single report out of several in Delphi / Lazarus / C++ Builder

    December 11, 2020

    I would like to note that FastReport VCL is one of the most convenient components

    read more
  • Make Drill-Down report in VCL (Delphi / Lazarus)

    February 9, 2021

    "Drill Down" or "deepening into data" is a concept with many sides, which can refer

    read more
  • How to create CODE 39 and CODE 39 Extended barcodes

    October 23, 2020

    CODE 39 is the barcode developed by Intermec Corporation in 1975. Up to 43 characters

    read more
  • How to generate ITF (interleaved, industrial, matrix) barcode with Delphi / Lazarus / C ++ Builder

    November 11, 2020

    A bit of theory about barcodes It is difficult to imagine our life without barcodes, especially

    read more

Using resources for storing FastReport reports

December 1, 2021

Sometimes you may need to restrict the users' ability to edit and copy reports. The key is to do it so that they would not even guess that the program uses such a wonderful product as FastReport. Let's talk about how to keep report templates hidden from prying eyes.

The idea is pretty simple: to store report templates inside an executable file, and to extract and execute them when you need it.

First, we will create report files in FastReport VCL and save them to the ReportList directory. Describe the resources through a text file with the following content:

1
2
TEST RCDATA ".\ReportList\Test.fr3"
TEST2 RCDATA ".\ReportList\Test2.fr3"

Let’s save the file with the name "TestFR.rc". Then we compile it with the BRCC32 TestFR.rc command and get TestFR.res. You need to add the following string to the beginning of the module:

1
{$R TestFR.res} 

You can make it easier using the RxLib library. After installing it, the Project Resources item will appear in the View menu. Select Project Resources-> New-> User Data and add the required report files.

Using resources for storing FastReport reports

Let's write a procedure for extracting the resource we need.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private
 { Private declarations }
 procedure LoadRptFromResource(Report: TfrxComponent; const ResName: string);
...............
procedure TFormMain.LoadRptFromResource(Report: TfrxComponent;
 const ResName: string);
var
 m: TResourceStream;
begin
 m := TResourceStream.Create(HInstance, ResName, RT_RCDATA);
 try
 m.Position := 0;
 Report.LoadFromStream(m);
 finally
 m.Free;
 end;
end;

Now let's write a print handler for our report.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
procedure TFormMain.Button1Click(Sender: TObject);
var
Report: TfrxReport;
begin
 
 Report:= frxReportMain ;
 Report.Preview := nil ;
 
 Report.Script.Variables['dDAT'] := Edit1.Text;
 
 //Report.LoadFromFile( ExtractFilePath(Application.ExeName) + 'ReportList\Test.fr3 ');
 //For checkout, it is still more convenient to use LoadFromFile. After checkout and after 
 //created the file for report resource description, you can apply the procedure LoadRptFromResource 
 LoadRptFromResource(Report, 'Test'); //loading report from resources
 Report.PrepareReport(True);
 
 //Report.LoadFromFile( ExtractFilePath(Application.ExeName) + 'ReportList\Test2.fr3 ');
 //
 LoadRptFromResource(Report, 'Test2'); // loading report from resources
 Report.PrepareReport(False);
 
 Report.Preview:= PreviewForm.frxPreviewMain;
 PreviewForm.ShowModal;
end;

Of course, this solution has flaws. The first one is the resource intensity of the program because the executable file increases several times, but packers compress it well. The second is the slow report generation.

The author of the article: Oleg Leontiev Gennadievich

about product buy
avatar
Den Zubov
VCL Development
Fast Reports Team: Den Zubov - VCL Development at Fast Reports
VCL Lazarus FastReport Delphi

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • FAQ
  • Tutorial Video
  • Forum
  • Support SLA
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Extended licensing
  • Contact us

© 1998-2023 by Fast Reports Inc.

  • Privacy Policy

Trustpilot