Create or design own Preview Form using Fortes report
In my last blog I have explained how to design Label reports by
using Fortes Report and its components. In this blog I will show you how to
design our own preview form using TRLPreview component that we can use to show saved
report files in .rpf format. And for
more detail about Fortes Report please visit Fortes Report and Components.
So now lets design Preview form with Fortes Report components.
1. First create a project and add a form to the project lets say
Unit1 (Form1).
2. Add TRLPreview component to the form and set Align=alClient.
And set following properties
RLPreview1: TRLPreview
Left = 0
Top = 22
Width = 866
Height = 488
HorzScrollBar.Tracking =
True
VertScrollBar.Tracking =
True
Align = alClient
TabOrder = 0
3. Add TToolbar component and set following properties. Here I
have not used any Timagelist to show images in buttons but we can use.
ToolBar1: TToolBar
Left = 0
Top = 0
Width = 866
Height = 22
AutoSize = True
ButtonWidth = 105
Caption = 'ToolBar1'
Font.Charset =
DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
List = True
ParentFont = False
ShowCaptions = True
4. Then add following buttons to the toolbar to implement
preview functions.
tbOpen: TToolButton
Left = 0
Top = 0
AutoSize = True
Caption = 'Open'
ImageIndex = 0
OnClick = tbOpenClick
tbSave: TToolButton
Left = 46
Top = 0
AutoSize = True
Caption = 'Save'
ImageIndex = 2
OnClick = tbSaveClick
tbPrint: TToolButton
Left = 90
Top = 0
AutoSize = True
Caption = 'Print'
ImageIndex = 2
OnClick = tbPrintClick
tbFirst: TToolButton
Left = 132
Top = 0
AutoSize = True
Caption = 'First Page'
ImageIndex = 2
OnClick = tbFirstClick
tbprior: TToolButton
Left = 205
Top = 0
AutoSize = True
Caption = 'Prior Page'
ImageIndex = 3
OnClick = tbpriorClick
spinPage: TSpinEdit
Left = 280
Top = 0
Width = 41
Height = 26
MaxValue = 0
MinValue = 0
TabOrder = 0
Value = 0
OnChange = spinPageChange
tbNext: TToolButton
Left = 321
Top = 0
AutoSize = True
Caption = 'Next Page'
ImageIndex = 4
OnClick = tbNextClick
tblast: TToolButton
Left = 394
Top = 0
AutoSize = True
Caption = 'Last Page'
ImageIndex = 5
OnClick = tblastClick
tbZoomin: TToolButton
Left = 465
Top = 0
AutoSize = True
Caption = 'Zoom +'
ImageIndex = 6
OnClick = tbZoominClick
tbZoomOut: TToolButton
Left = 525
Top = 0
AutoSize = True
Caption = 'Zoom -'
ImageIndex = 7
OnClick = tbZoomOutClick
tbZoomFullPage:
TToolButton
Left = 582
Top = 0
AutoSize = True
Caption = 'Zoom Full
Page'
ImageIndex = 8
OnClick =
tbZoomFullPageClick
tbZoomFullWidth:
TToolButton
Left = 686
Top = 0
AutoSize = True
Caption = 'Zoom Full
Width'
ImageIndex = 9
OnClick =
tbZoomFullWidthClick
tbExit: TToolButton
Left = 795
Top = 0
AutoSize = True
Caption = 'Exit'
ImageIndex = 1
OnClick = tbExitClick
5. Put report filter components on form to save report in
different format during preview
RLRichFilter1:
TRLRichFilter;
RLPDFFilter1: TRLPDFFilter;
RLXLSFilter1: TRLXLSFilter;
RLHTMLFilter1:
TRLHTMLFilter;
6. Add a procedure to open Fortes Report files on preview form.
//TO
SHOW A REPORT FILE SAVE IN .RFP FORMAT//
procedure TForm1.ShowreportFile(sFile: string);
begin
if sFile <> '' then
begin
RLPreview1.Pages := Nil;
RLPreview1.Pages :=
TRLGraphicStorage.Create(Self);
RLPreview1.Pages.LoadFromFile(sFile);
RLPreview1.PageNumber :=
RLPreview1.Pages.FirstPageNumber;
RLPreview1.ZoomFactor :=
100;
RLPreview1.ZoomFullWidth;
spinPage.Value :=
RLPreview1.PageNumber;
spinPage.MinValue :=
RLPreview1.Pages.FirstPageNumber;
spinPage.MaxValue :=
RLPreview1.Pages.LastPageNumber;
end;
end;
7. Open button click event
procedure TForm1.tbOpenClick(Sender:
TObject);
begin
if OpenDialog1.Execute then
begin
ShowreportFile(OpenDialog1.FileName);
Caption := 'Preview ->
'+ OpenDialog1.FileName;
end;
end;
8. Save button click event. For this add RLSaveDialog Fortes report unit to uses clause to access
TRLSaveDialog form.
procedure TForm1.tbSaveClick(Sender: TObject);
var
SaveDlg: TRLSaveDialog;
SaveFilter:
TRLCustomSaveFilter;
begin
SaveDlg :=
TRLSaveDialog.CreateNew(Nil);
SaveDlg.FromPage :=
RLPreview1.Pages.FirstPageNumber;
SaveDlg.ToPage :=
RLPreview1.Pages.LastPageNumber;
if SaveDlg.Execute then
begin
if SelectedFilter
<> Nil then
SaveFilter :=
TRLCustomSaveFilter(SelectedFilter)
else
SaveFilter :=
SaveFilterByFileName(SaveDlg.FileName);
if SaveFilter <>
Nil then
begin
SaveFilter.FileName :=
SaveDlg.FileName;
SaveFilter.FilterPages(RLPreview1.Pages,
SaveDlg.FromPage, SaveDlg.ToPage, '', 0);
end
else
RLPreview1.Pages.SaveToFile(SaveDlg.FileName);
end;
end;
9. Print button click event. For this add RLPrintDialog Fortes report unit to uses clause to access TRLPrintDialog
form.
procedure TForm1.tbPrintClick(Sender: TObject);
var
PrintDialog:
TRLPrintDialog;
begin
PrintDialog :=
TRLPrintDialog.CreateNew(Nil);
PrintDialog.FromPage :=
RLPreview1.Pages.FirstPageNumber;
PrintDialog.ToPage :=
RLPreview1.Pages.LastPageNumber;
if PrintDialog.Execute then
begin
FilterPages(RLPreview1.Pages, Nil, PrintDialog.FromPage,
PrintDialog.ToPage, PrintDialog.PageRanges, 0);
end;
end;
10. First button click event.
procedure TForm1.tbFirstClick(Sender: TObject);
begin
RLPreview1.FirstPage;
spinPage.Value :=
RLPreview1.PageNumber;
end;
11. Prior button click event.
procedure TForm1.tbpriorClick(Sender: TObject);
begin
RLPreview1.PriorPage;
spinPage.Value :=
RLPreview1.PageNumber;
end;
12. Next button click event.
procedure TForm1.tbNextClick(Sender: TObject);
begin
RLPreview1.NextPage;
spinPage.Value :=
RLPreview1.PageNumber;
end;
13. Last button click event.
procedure TForm1.tblastClick(Sender: TObject);
begin
RLPreview1.LastPage;
spinPage.Value :=
RLPreview1.PageNumber;
end;
14. ZoomIn button click event.
procedure TForm1.tbZoominClick(Sender: TObject);
begin
RLPreview1.ZoomFactor :=
RLPreview1.ZoomFactor+10;
RLPreview1.ZoomIn();
end;
15. ZoomOut button click event.
procedure TForm1.tbZoomOutClick(Sender: TObject);
begin
RLPreview1.ZoomFactor :=
RLPreview1.ZoomFactor-10;
RLPreview1.ZoomOut();
end;
16. ZoomFullPage button click event.
procedure TForm1.tbZoomFullPageClick(Sender: TObject);
begin
RLPreview1.ZoomFullPage;
end;
17. ZoomFullWidth button click event.
procedure TForm1.tbZoomFullWidthClick(Sender: TObject);
begin
RLPreview1.ZoomFullWidth;
end;
18. Exit button click event.
procedure TForm1.tbExitClick(Sender: TObject);
begin
Close;
end;
procedure
TForm1.spinPageChange(Sender: TObject);
begin
RLPreview1.PageNumber := spinPage.Value;
end;
20. On Form Close.
procedure TForm1.FormClose(Sender: TObject; var Action:
TCloseAction);
begin
Action := caFree;
end;
Now click on Open and
select a saved Fortes Report file in .rpf format to preview.
Create or design simple master report with Fortes Report
Create or Design master detail report with Fortes Report
Create or Design reports with Groups in Fortes Report
Create or design Labels with Fortes Report
How I can make a report type master-detil-detail-detail- ...
ReplyDelete