Skip to content

Instantly share code, notes, and snippets.

@dipold
Created September 11, 2018 13:00
Show Gist options
  • Save dipold/5c7e68147ea1371434b4aa9cd7c56494 to your computer and use it in GitHub Desktop.
Save dipold/5c7e68147ea1371434b4aa9cd7c56494 to your computer and use it in GitHub Desktop.
FastReport Example: Display data in TfrxReport from Business Object using TfrxUserDataSet
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 242
ClientWidth = 472
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object frxReport1: TfrxReport
Version = '5.6.1'
DotMatrixReport = False
IniFile = '\Software\Fast Reports'
PreviewOptions.Buttons = [pbPrint, pbLoad, pbSave, pbExport, pbZoom, pbFind, pbOutline, pbPageSetup, pbTools, pbEdit, pbNavigator, pbExportQuick]
PreviewOptions.Zoom = 1.000000000000000000
PrintOptions.Printer = 'Padr'#227'o'
PrintOptions.PrintOnSheet = 0
ReportOptions.CreateDate = 43354.359786655090000000
ReportOptions.LastChange = 43354.359786655090000000
ScriptLanguage = 'PascalScript'
ScriptText.Strings = (
'begin'
''
'end.')
Left = 216
Top = 24
Datasets = <
item
DataSet = DSCars
DataSetName = 'DSCars'
end
item
DataSet = DSPerson
DataSetName = 'DSPerson'
end
item
DataSet = DSPets
DataSetName = 'DSPets'
end>
Variables = <>
Style = <>
object Data: TfrxDataPage
Height = 1000.000000000000000000
Width = 1000.000000000000000000
end
object Page1: TfrxReportPage
PaperWidth = 210.000000000000000000
PaperHeight = 297.000000000000000000
PaperSize = 9
LeftMargin = 10.000000000000000000
RightMargin = 10.000000000000000000
TopMargin = 10.000000000000000000
BottomMargin = 10.000000000000000000
object MasterData1: TfrxMasterData
FillType = ftBrush
Height = 22.677180000000000000
Top = 18.897650000000000000
Width = 718.110700000000000000
DataSet = DSPerson
DataSetName = 'DSPerson'
RowCount = 1
object DSPessoaId: TfrxMemoView
Left = 3.779530000000000000
Width = 128.504020000000000000
Height = 18.897650000000000000
DataField = 'Id'
DataSet = DSPerson
DataSetName = 'DSPerson'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSPerson."Id"]')
ParentFont = False
end
object DSPessoaNome: TfrxMemoView
Left = 136.063080000000000000
Width = 294.803340000000000000
Height = 18.897650000000000000
DataSet = DSPerson
DataSetName = 'DSPerson'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSPerson."Name"]')
ParentFont = False
end
end
object DetailData1: TfrxDetailData
FillType = ftBrush
Height = 22.677180000000000000
Top = 64.252010000000000000
Width = 718.110700000000000000
DataSet = DSCars
DataSetName = 'DSCars'
RowCount = 0
object DSCarsId: TfrxMemoView
Left = 45.354360000000000000
Width = 79.370130000000000000
Height = 18.897650000000000000
DataField = 'Id'
DataSet = DSCars
DataSetName = 'DSCars'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSCars."Id"]')
ParentFont = False
end
object DSCarsModelo: TfrxMemoView
Left = 132.283550000000000000
Width = 294.803340000000000000
Height = 18.897650000000000000
DataSet = DSCars
DataSetName = 'DSCars'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSCars."Model"]')
ParentFont = False
end
end
object DetailData2: TfrxDetailData
FillType = ftBrush
Height = 22.677180000000000000
Top = 109.606370000000000000
Width = 718.110700000000000000
DataSet = DSPets
DataSetName = 'DSPets'
RowCount = 0
object DSPetsId: TfrxMemoView
Left = 45.354360000000000000
Width = 79.370130000000000000
Height = 18.897650000000000000
DataField = 'Id'
DataSet = DSPets
DataSetName = 'DSPets'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSPets."Id"]')
ParentFont = False
end
object Memo1: TfrxMemoView
Left = 132.283550000000000000
Width = 294.803340000000000000
Height = 18.897650000000000000
DataSet = DSPets
DataSetName = 'DSPets'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Memo.UTF8W = (
'[DSPets."Breed"]')
ParentFont = False
end
end
end
end
object DSPerson: TfrxUserDataSet
UserName = 'DSPerson'
Fields.Strings = (
'Id'
'Name')
OnGetValue = DSPersonGetValue
Left = 216
Top = 80
end
object DSCars: TfrxUserDataSet
UserName = 'DSCars'
Fields.Strings = (
'Id'
'Model')
OnGetValue = DSCarsGetValue
Left = 168
Top = 136
end
object DSPets: TfrxUserDataSet
UserName = 'DSPets'
Fields.Strings = (
'Id'
'Breed')
OnGetValue = DSPetsGetValue
Left = 248
Top = 136
end
end
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, system.generics.collections, frxClass;
type
TCar = class
public
FId: Integer;
FModel: String;
end;
TPet = class
public
FId: Integer;
FBreed: String;
end;
TPerson = class
public
FId: Integer;
FNome: String;
FCars: TList<TCar>;
FPets: TList<TPet>;
constructor Create;
end;
TForm1 = class(TForm)
frxReport1: TfrxReport;
DSPerson: TfrxUserDataSet;
DSCars: TfrxUserDataSet;
DSPets: TfrxUserDataSet;
procedure FormCreate(Sender: TObject);
procedure DSPersonGetValue(const VarName: string; var Value: Variant);
procedure FormShow(Sender: TObject);
procedure DSCarsGetValue(const VarName: string; var Value: Variant);
procedure DSPetsGetValue(const VarName: string; var Value: Variant);
private
FPerson: TPerson;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TPessoa }
constructor TPerson.Create;
begin
FCars := TList<TCar>.Create;
FPets := TList<TPet>.Create;
end;
procedure TForm1.DSCarsGetValue(const VarName: string; var Value: Variant);
begin
if (VarName = 'Id') then
Value := FPerson.FCars[DSCars.RecNo].FId;
if (VarName = 'Model') then
Value := FPerson.FCars[DSCars.RecNo].FModel;
end;
procedure TForm1.DSPersonGetValue(const VarName: string; var Value: Variant);
begin
if (VarName = 'Id') then
Value := FPerson.FId;
if (VarName = 'Name') then
Value := FPerson.FNome;
end;
procedure TForm1.DSPetsGetValue(const VarName: string; var Value: Variant);
begin
if (VarName = 'Id') then
Value := FPerson.FPets[DSPets.RecNo].FId;
if (VarName = 'Breed') then
Value := FPerson.FPets[DSPets.RecNo].FBreed;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FPerson := TPerson.Create;
FPerson.FId := 1;
FPerson.FNome := 'Person Name';
FPerson.FCars.Add(TCar.Create);
FPerson.FCars.Add(TCar.Create);
FPerson.FCars[0].FId := 1;
FPerson.FCars[0].FModel := 'Honda Civic';
FPerson.FCars[1].FId := 2;
FPerson.FCars[1].FModel := 'BMW E320';
FPerson.FPets.Add(TPet.Create);
FPerson.FPets.Add(TPet.Create);
FPerson.FPets[0].FId := 1;
FPerson.FPets[0].FBreed := 'Samoieda';
FPerson.FPets[1].FId := 2;
FPerson.FPets[1].FBreed := 'Pastor Alemão';
DSPerson.RangeEnd := reCurrent;
DSCars.RangeEnd := reCount;
DSPets.RangeEnd := reCount;
DSCars.RangeEndCount := FPerson.FCars.Count;
DSPets.RangeEndCount := FPerson.FPets.Count;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
frxReport1.ShowReport;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment