├── 9781484222133.jpg
├── Chapter 2
├── Database.pas
├── Declarations.pas
├── InvoiceForm.fmx
├── InvoiceForm.pas
├── MainScreenForm.fmx
├── MainScreenForm.pas
├── POSApp.dpr
├── POSApp.dproj
├── POSApp.res
└── POSAppProject.groupproj
├── Chapter 3
├── POSAppMVVM
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Main.pas
│ │ └── __history
│ │ │ ├── Model.Database.pas.~1~
│ │ │ ├── Model.Database.pas.~2~
│ │ │ ├── Model.Database.pas.~3~
│ │ │ ├── Model.Database.pas.~4~
│ │ │ ├── Model.Database.pas.~5~
│ │ │ ├── Model.Declarations.pas.~1~
│ │ │ ├── Model.Declarations.pas.~2~
│ │ │ ├── Model.Declarations.pas.~3~
│ │ │ ├── Model.Declarations.pas.~4~
│ │ │ ├── Model.Declarations.pas.~5~
│ │ │ ├── Model.Declarations.pas.~6~
│ │ │ ├── Model.Declarations.pas.~7~
│ │ │ ├── Model.Declarations.pas.~8~
│ │ │ ├── Model.Main.pas.~1~
│ │ │ ├── Model.Main.pas.~2~
│ │ │ ├── Model.Main.pas.~3~
│ │ │ ├── Model.Main.pas.~4~
│ │ │ ├── Model.Main.pas.~5~
│ │ │ ├── Model.Main.pas.~6~
│ │ │ ├── Model.Main.pas.~7~
│ │ │ └── Model.Main.pas.~8~
│ ├── POSAppMVVM.dpr
│ ├── POSAppMVVM.dproj
│ ├── POSAppMVVM.dsk
│ ├── POSAppMVVMProjectGroup.groupproj
│ ├── ViewModels
│ │ ├── ViewModel.Main.pas
│ │ └── __history
│ │ │ ├── ViewModel.Main.pas.~10~
│ │ │ ├── ViewModel.Main.pas.~11~
│ │ │ ├── ViewModel.Main.pas.~2~
│ │ │ ├── ViewModel.Main.pas.~3~
│ │ │ ├── ViewModel.Main.pas.~4~
│ │ │ ├── ViewModel.Main.pas.~5~
│ │ │ ├── ViewModel.Main.pas.~6~
│ │ │ ├── ViewModel.Main.pas.~7~
│ │ │ ├── ViewModel.Main.pas.~8~
│ │ │ └── ViewModel.Main.pas.~9~
│ └── Views
│ │ ├── View.MainForm.fmx
│ │ ├── View.MainForm.pas
│ │ └── __history
│ │ ├── View.MainForm.fmx.~10~
│ │ ├── View.MainForm.fmx.~11~
│ │ ├── View.MainForm.fmx.~2~
│ │ ├── View.MainForm.fmx.~3~
│ │ ├── View.MainForm.fmx.~4~
│ │ ├── View.MainForm.fmx.~5~
│ │ ├── View.MainForm.fmx.~6~
│ │ ├── View.MainForm.fmx.~7~
│ │ ├── View.MainForm.fmx.~8~
│ │ ├── View.MainForm.fmx.~9~
│ │ ├── View.MainForm.pas.~10~
│ │ ├── View.MainForm.pas.~11~
│ │ ├── View.MainForm.pas.~12~
│ │ ├── View.MainForm.pas.~13~
│ │ ├── View.MainForm.pas.~14~
│ │ ├── View.MainForm.pas.~15~
│ │ ├── View.MainForm.pas.~16~
│ │ ├── View.MainForm.pas.~17~
│ │ ├── View.MainForm.pas.~18~
│ │ ├── View.MainForm.pas.~9~
│ │ ├── View.TestPrintInvoice.fmx.~1~
│ │ ├── View.TestPrintInvoice.fmx.~2~
│ │ ├── View.TestPrintInvoice.fmx.~3~
│ │ ├── View.TestPrintInvoice.fmx.~4~
│ │ ├── View.TestPrintInvoice.fmx.~5~
│ │ ├── View.TestPrintInvoice.pas.~1~
│ │ ├── View.TestPrintInvoice.pas.~2~
│ │ ├── View.TestPrintInvoice.pas.~3~
│ │ ├── View.TestPrintInvoice.pas.~4~
│ │ ├── View.TestPrintInvoice.pas.~5~
│ │ └── View.TestPrintInvoice.pas.~6~
├── POSAppMVVMMainForm
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMMainForm.dpr
│ ├── POSAppMVVMMainForm.dproj
│ ├── POSAppMVVMMainForm.res
│ ├── POSAppMVVMMainFormProjectGroup.groupproj
│ ├── ViewModels
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
└── Thin Forms
│ ├── View.MainForm.fmx
│ └── View.MainForm.pas
├── Chapter 4
├── POSAppMVVMMainFormFullInterfaces
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMMainFormFullInterfaces.dpr
│ ├── POSAppMVVMMainFormFullInterfaces.dproj
│ ├── POSAppMVVMMainFormFullInterfaces.res
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
├── POSAppMVVMMainFormInterfaces
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMMainFormInterfaces.dpr
│ ├── POSAppMVVMMainFormInterfaces.dproj
│ ├── POSAppMVVMMainFormInterfaces.res
│ ├── POSAppMVVMMainFormInterfacesProjectGroup.groupproj
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.MainForm.fmx
│ │ ├── View.MainForm.pas
│ │ ├── View.TestPrintInvoice.fmx
│ │ └── View.TestPrintInvoice.pas
└── POSAppMVVMMainFormTest
│ ├── Models
│ ├── Model.Database.pas
│ ├── Model.Declarations.pas
│ └── Model.Main.pas
│ ├── POSAppMVVMMainFormTest.dpr
│ ├── POSAppMVVMMainFormTest.dproj
│ ├── POSAppMVVMMainFormTest.dsk
│ ├── POSAppMVVMMainFormTest.stat
│ ├── POSAppMVVMMainFormTestProjectGroup.groupproj
│ ├── SupportCode
│ ├── Model.ProSu.InterfaceActions.pas
│ ├── Model.ProSu.Interfaces.pas
│ ├── Model.ProSu.Provider.pas
│ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ └── ViewModel.Main.pas
│ └── Views
│ ├── View.MainForm.fmx
│ ├── View.MainForm.pas
│ ├── View.TestPrintInvoice.fmx
│ └── View.TestPrintInvoice.pas
├── Chapter 5
├── POSAppMVVMInvoiceForm
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ ├── Model.Invoice.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMInvoiceForm.dpr
│ ├── POSAppMVVMInvoiceForm.dproj
│ ├── POSAppMVVMInvoiceFormProjectGroup.groupproj
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ ├── ViewModel.Invoice.pas
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.InvoiceForm.fmx
│ │ ├── View.InvoiceForm.pas
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
├── POSAppMVVMMainFormFullInterfaces
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMMainFormFullInterfaces.dpr
│ ├── POSAppMVVMMainFormFullInterfaces.dproj
│ ├── POSAppMVVMMainFormFullInterfaces.res
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.MainForm.fmx
│ │ ├── View.MainForm.pas
│ │ └── __history
│ │ ├── View.MainForm.fmx.~1~
│ │ ├── View.MainForm.fmx.~2~
│ │ ├── View.MainForm.fmx.~3~
│ │ ├── View.MainForm.fmx.~4~
│ │ ├── View.MainForm.fmx.~5~
│ │ ├── View.MainForm.fmx.~6~
│ │ ├── View.MainForm.fmx.~7~
│ │ ├── View.MainForm.pas.~11~
│ │ ├── View.MainForm.pas.~12~
│ │ ├── View.MainForm.pas.~13~
│ │ ├── View.MainForm.pas.~14~
│ │ ├── View.MainForm.pas.~15~
│ │ ├── View.MainForm.pas.~16~
│ │ ├── View.MainForm.pas.~17~
│ │ ├── View.MainForm.pas.~18~
│ │ ├── View.MainForm.pas.~19~
│ │ ├── View.MainForm.pas.~20~
│ │ ├── View.TestPrintInvoice.fmx.~1~
│ │ ├── View.TestPrintInvoice.fmx.~2~
│ │ ├── View.TestPrintInvoice.fmx.~3~
│ │ ├── View.TestPrintInvoice.fmx.~4~
│ │ ├── View.TestPrintInvoice.pas.~1~
│ │ ├── View.TestPrintInvoice.pas.~2~
│ │ ├── View.TestPrintInvoice.pas.~3~
│ │ └── View.TestPrintInvoice.pas.~4~
├── POSAppMVVMStart
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMStart.dpr
│ ├── POSAppMVVMStart.dproj
│ ├── POSAppMVVMStartProjectGroup.groupproj
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.InvoiceForm.fmx
│ │ ├── View.InvoiceForm.pas
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
└── Thin Forms
│ ├── View.InvoiceForm.fmx
│ └── View.InvoiceForm.pas
├── Chapter 6
├── POSAppMVVMInvoiceForm
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ ├── Model.Invoice.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMInvoiceForm.dpr
│ ├── POSAppMVVMInvoiceForm.dproj
│ ├── POSAppMVVMInvoiceForm.stat
│ ├── POSAppMVVMInvoiceFormProjectGroup.groupproj
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ ├── ViewModel.Invoice.pas
│ │ └── ViewModel.Main.pas
│ └── Views
│ │ ├── View.InvoiceForm.fmx
│ │ ├── View.InvoiceForm.pas
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
└── POSAppMVVMUserInteraction
│ ├── Models
│ ├── Model.Database.pas
│ ├── Model.Declarations.pas
│ ├── Model.Interfaces.pas
│ ├── Model.Invoice.pas
│ └── Model.Main.pas
│ ├── POSAppMVVMUserInteraction.dpr
│ ├── POSAppMVVMUserInteraction.dproj
│ ├── POSAppMVVMUserInteractionProjectGroup.groupproj
│ ├── SupportCode
│ ├── Model.ProSu.InterfaceActions.pas
│ ├── Model.ProSu.Interfaces.pas
│ ├── Model.ProSu.Provider.pas
│ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ ├── ViewModel.Invoice.pas
│ └── ViewModel.Main.pas
│ └── Views
│ ├── View.InvoiceForm.fmx
│ ├── View.InvoiceForm.pas
│ ├── View.MainForm.fmx
│ └── View.MainForm.pas
├── Chapter 7
├── POSAppMVVMFinal
│ ├── Models
│ │ ├── Model.Database.pas
│ │ ├── Model.Declarations.pas
│ │ ├── Model.Interfaces.pas
│ │ ├── Model.Invoice.pas
│ │ └── Model.Main.pas
│ ├── POSAppMVVMFinal.dpr
│ ├── POSAppMVVMFinal.dproj
│ ├── POSAppMVVMFinalProjectGroup.groupproj
│ ├── SupportCode
│ │ ├── Model.ProSu.InterfaceActions.pas
│ │ ├── Model.ProSu.Interfaces.pas
│ │ ├── Model.ProSu.Provider.pas
│ │ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ │ ├── ViewModel.Invoice.pas
│ │ └── ViewModel.Main.pas
│ ├── Views
│ │ ├── View.InvoiceForm.fmx
│ │ ├── View.InvoiceForm.pas
│ │ ├── View.MainForm.fmx
│ │ └── View.MainForm.pas
│ └── Win32
│ │ └── Debug
│ │ ├── Model.Database.dcu
│ │ ├── Model.Declarations.dcu
│ │ ├── Model.Interfaces.dcu
│ │ ├── Model.Invoice.dcu
│ │ ├── Model.Main.dcu
│ │ ├── Model.ProSu.InterfaceActions.dcu
│ │ ├── Model.ProSu.Interfaces.dcu
│ │ ├── Model.ProSu.Provider.dcu
│ │ ├── Model.ProSu.Subscriber.dcu
│ │ ├── POSAppMVVMFinal.drc
│ │ ├── POSAppMVVMFinal.exe
│ │ ├── POSAppMVVMFinal.map
│ │ ├── View.InvoiceForm.dcu
│ │ ├── View.MainForm.dcu
│ │ ├── ViewModel.Invoice.dcu
│ │ └── ViewModel.Main.dcu
└── POSAppMVVMUserInteraction
│ ├── Models
│ ├── Model.Database.pas
│ ├── Model.Declarations.pas
│ ├── Model.Interfaces.pas
│ ├── Model.Invoice.pas
│ └── Model.Main.pas
│ ├── POSAppMVVMUserInteraction.dpr
│ ├── POSAppMVVMUserInteraction.dproj
│ ├── POSAppMVVMUserInteractionProjectGroup.groupproj
│ ├── SupportCode
│ ├── Model.ProSu.InterfaceActions.pas
│ ├── Model.ProSu.Interfaces.pas
│ ├── Model.ProSu.Provider.pas
│ └── Model.ProSu.Subscriber.pas
│ ├── ViewModels
│ ├── ViewModel.Invoice.pas
│ └── ViewModel.Main.pas
│ └── Views
│ ├── View.InvoiceForm.fmx
│ ├── View.InvoiceForm.pas
│ ├── View.MainForm.fmx
│ └── View.MainForm.pas
├── LICENSE.txt
├── README.md
└── contributing.md
/9781484222133.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/9781484222133.jpg
--------------------------------------------------------------------------------
/Chapter 2/Declarations.pas:
--------------------------------------------------------------------------------
1 | unit Declarations;
2 |
3 | {********************************}
4 | { This unit defines the classes }
5 | {********************************}
6 |
7 | interface
8 |
9 | type
10 | TCustomer = class
11 | private
12 | fID: Integer;
13 | fName: string;
14 | fDiscountRate: Double;
15 | fBalance: Currency;
16 | public
17 | property ID: integer read fID write fID;
18 | property Name: string read fName write fName;
19 | property DiscountRate: double read fDiscountRate write fDiscountRate;
20 | property Balance: Currency read fBalance write fBalance;
21 | end;
22 |
23 | TItem = class
24 | private
25 | fID: Integer;
26 | fDescription: string;
27 | fPrice: Currency;
28 | public
29 | property ID: integer read fID write fID;
30 | property Description: string read fDescription write fDescription;
31 | property Price: Currency read fPrice write fPrice;
32 | end;
33 |
34 | TInvoice = class
35 | private
36 | fID: integer;
37 | fNumber: integer;
38 | fCustomerID: Integer;
39 | public
40 | property ID: Integer read fID write fID;
41 | property Number: Integer read fNumber write fNumber;
42 | property CustomerID: Integer read fCustomerID write fCustomerID;
43 | end;
44 |
45 | TInvoiceItem = class
46 | private
47 | fID: integer;
48 | fInvoiceID: integer;
49 | fItemID: integer;
50 | fUnitPrice: Currency;
51 | fQuantity: integer;
52 | public
53 | property ID: integer read fID write fID;
54 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
55 | property ItemID: integer read fItemID write fItemID;
56 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
57 | property Quantity: Integer read fQuantity write fQuantity;
58 | end;
59 |
60 | implementation
61 |
62 | end.
63 |
--------------------------------------------------------------------------------
/Chapter 2/MainScreenForm.fmx:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'POSApp'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object LabelTitle: TLabel
13 | Align = Top
14 | StyledSettings = [Family, FontColor]
15 | Margins.Left = 20.000000000000000000
16 | Margins.Top = 20.000000000000000000
17 | Margins.Right = 20.000000000000000000
18 | Position.X = 20.000000000000000000
19 | Position.Y = 20.000000000000000000
20 | Size.Width = 320.000000000000000000
21 | Size.Height = 50.000000000000000000
22 | Size.PlatformDefault = False
23 | TextSettings.Font.Size = 24.000000000000000000
24 | TextSettings.Font.Style = [fsBold]
25 | TextSettings.HorzAlign = Center
26 | Text = 'Main Screen'
27 | end
28 | object ButtonInvoice: TButton
29 | Position.X = 96.000000000000000000
30 | Position.Y = 93.000000000000000000
31 | Size.Width = 167.000000000000000000
32 | Size.Height = 76.000000000000000000
33 | Size.PlatformDefault = False
34 | TabOrder = 1
35 | Text = 'Issue Invoice'
36 | OnClick = ButtonInvoiceClick
37 | end
38 | object LabelTotalSalesText: TLabel
39 | StyledSettings = [Family, FontColor]
40 | Position.X = 16.000000000000000000
41 | Position.Y = 200.000000000000000000
42 | Size.Width = 153.000000000000000000
43 | Size.Height = 25.000000000000000000
44 | Size.PlatformDefault = False
45 | TextSettings.Font.Size = 22.000000000000000000
46 | TextSettings.Font.Style = [fsBold]
47 | Text = 'Total Sales:'
48 | end
49 | object LabelTotalSalesFigure: TLabel
50 | StyledSettings = [Family]
51 | Position.X = 168.000000000000000000
52 | Position.Y = 200.000000000000000000
53 | Size.Width = 169.000000000000000000
54 | Size.Height = 25.000000000000000000
55 | Size.PlatformDefault = False
56 | TextSettings.Font.Size = 22.000000000000000000
57 | TextSettings.Font.Style = [fsBold]
58 | TextSettings.FontColor = claGreen
59 | TextSettings.HorzAlign = Trailing
60 | Text = '0'
61 | end
62 | end
63 |
--------------------------------------------------------------------------------
/Chapter 2/MainScreenForm.pas:
--------------------------------------------------------------------------------
1 | unit MainScreenForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8 | FMX.Controls.Presentation, InvoiceForm, Database;
9 |
10 | type
11 | TMainForm = class(TForm)
12 | LabelTitle: TLabel;
13 | ButtonInvoice: TButton;
14 | LabelTotalSalesText: TLabel;
15 | LabelTotalSalesFigure: TLabel;
16 | procedure ButtonInvoiceClick(Sender: TObject);
17 | procedure FormCreate(Sender: TObject);
18 | private
19 | // Updates the TotalSalesFigure Label with the figure retrieved from the
20 | // database.
21 | procedure UpdateTotalSales;
22 | public
23 | { Public declarations }
24 | end;
25 |
26 | var
27 | MainForm: TMainForm;
28 |
29 | implementation
30 |
31 | {$R *.fmx}
32 |
33 | procedure TMainForm.ButtonInvoiceClick(Sender: TObject);
34 | var
35 | tmpInvoiceForm: TSalesInvoiceForm;
36 | begin
37 | tmpInvoiceForm:=TSalesInvoiceForm.Create(self);
38 | tmpInvoiceForm.ShowModal;
39 | UpdateTotalSales;
40 | end;
41 |
42 | procedure TMainForm.FormCreate(Sender: TObject);
43 | begin
44 | UpdateTotalSales;
45 | end;
46 |
47 | procedure TMainForm.UpdateTotalSales;
48 | var
49 | tmpSales: Currency;
50 | tmpDatabase: TDatabase;
51 | begin
52 | tmpSales:=0.00;
53 | tmpDatabase:=TDatabase.Create;
54 | tmpSales:=tmpDatabase.GetTotalSales;
55 | tmpDatabase.Free;
56 | LabelTotalSalesFigure.Text:=Format('%10.2f',[tmpSales]);
57 | end;
58 |
59 | end.
60 |
61 |
62 | uses Database;
63 |
--------------------------------------------------------------------------------
/Chapter 2/POSApp.dpr:
--------------------------------------------------------------------------------
1 | program POSApp;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | InvoiceForm in 'InvoiceForm.pas' {SalesInvoiceForm},
7 | Declarations in 'Declarations.pas',
8 | Database in 'Database.pas',
9 | MainScreenForm in 'MainScreenForm.pas' {MainForm};
10 |
11 | {$R *.res}
12 |
13 | begin
14 | Application.Initialize;
15 | Application.CreateForm(TMainForm, MainForm);
16 | Application.Run;
17 | end.
18 |
--------------------------------------------------------------------------------
/Chapter 2/POSApp.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 2/POSApp.res
--------------------------------------------------------------------------------
/Chapter 2/POSAppProject.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {9562C888-862B-47F1-92A0-D8DF901189A4}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/Model.Declarations.pas:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | fCustomerID: integer;
35 | public
36 | property ID: Integer read fID write fID;
37 | property Number: Integer read fNumber write fNumber;
38 | property CustomerID: Integer read fCustomerID write fCustomerID;
39 | end;
40 |
41 | TInvoiceItem = class
42 | private
43 | fID: integer;
44 | fInvoiceID: integer;
45 | fItemID: integer;
46 | fUnitPrice: Currency;
47 | fQuantity: integer;
48 | public
49 | property ID: integer read fID write fID;
50 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
51 | property ItemID: integer read fItemID write fItemID;
52 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
53 | property Quantity: Integer read fQuantity write fQuantity;
54 | end;
55 |
56 | TMainFormLabelsText = record
57 | Title,
58 | IssueButtonCaption,
59 | TotalSalesText: string;
60 | end;
61 |
62 | implementation
63 |
64 | end.
65 |
66 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fDatabase:=TDatabase.Create;
29 | end;
30 |
31 | destructor TMainModel.Destroy;
32 | begin
33 | fDatabase.Free;
34 | inherited;
35 | end;
36 |
37 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
38 | begin
39 | fMainFormLabelsText.Title:='Main Screen';
40 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
41 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
42 | result:=fMainFormLabelsText;
43 | end;
44 |
45 | function TMainModel.GetTotalSales: Currency;
46 | begin
47 | result:=fDatabase.GetTotalSales;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~1~:
--------------------------------------------------------------------------------
1 | unit Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | public
35 | property ID: Integer read fID write fID;
36 | property Number: Integer read fNumber write fNumber;
37 | end;
38 | TInvoiceItem = class
39 | private
40 | fID: integer;
41 | fInvoiceID: integer;
42 | fItemID: integer;
43 | fUnitPrice: Currency;
44 | fQuantity: integer;
45 | public
46 | property ID: integer read fID write fID;
47 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
48 | property ItemID: integer read fItemID write fItemID;
49 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
50 | property Quantity: Integer read fQuantity write fQuantity;
51 | end;
52 |
53 | implementation
54 |
55 | end.
56 |
57 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~2~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | public
35 | property ID: Integer read fID write fID;
36 | property Number: Integer read fNumber write fNumber;
37 | end;
38 | TInvoiceItem = class
39 | private
40 | fID: integer;
41 | fInvoiceID: integer;
42 | fItemID: integer;
43 | fUnitPrice: Currency;
44 | fQuantity: integer;
45 | public
46 | property ID: integer read fID write fID;
47 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
48 | property ItemID: integer read fItemID write fItemID;
49 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
50 | property Quantity: Integer read fQuantity write fQuantity;
51 | end;
52 |
53 | implementation
54 |
55 | end.
56 |
57 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~3~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | public
35 | property ID: Integer read fID write fID;
36 | property Number: Integer read fNumber write fNumber;
37 | end;
38 | TInvoiceItem = class
39 | private
40 | fID: integer;
41 | fInvoiceID: integer;
42 | fItemID: integer;
43 | fUnitPrice: Currency;
44 | fQuantity: integer;
45 | public
46 | property ID: integer read fID write fID;
47 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
48 | property ItemID: integer read fItemID write fItemID;
49 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
50 | property Quantity: Integer read fQuantity write fQuantity;
51 | end;
52 |
53 | TMainFormLabelsText = record
54 | Title,
55 | IssueButtonCaption,
56 | TotalSalesText,
57 | TotalSalesEmptyText: string;
58 | end;
59 |
60 | implementation
61 |
62 | end.
63 |
64 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~4~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | uses
6 | Model.ProSu.InterfaceActions, Model.ProSu.Interfaces;
7 |
8 | type
9 | TCustomer = class
10 | private
11 | fID: Integer;
12 | fName: string;
13 | fDiscountRate: Double;
14 | fBalance: Currency;
15 | public
16 | property ID: integer read fID write fID;
17 | property Name: string read fName write fName;
18 | property DiscountRate: double read fDiscountRate write fDiscountRate;
19 | property Balance: Currency read fBalance write fBalance;
20 | end;
21 |
22 | TItem = class
23 | private
24 | fID: Integer;
25 | fDescription: string;
26 | fPrice: Currency;
27 | public
28 | property ID: integer read fID write fID;
29 | property Description: string read fDescription write fDescription;
30 | property Price: Currency read fPrice write fPrice;
31 | end;
32 |
33 | TInvoice = class
34 | private
35 | fID: integer;
36 | fNumber: integer;
37 | public
38 | property ID: Integer read fID write fID;
39 | property Number: Integer read fNumber write fNumber;
40 | end;
41 | TInvoiceItem = class
42 | private
43 | fID: integer;
44 | fInvoiceID: integer;
45 | fItemID: integer;
46 | fUnitPrice: Currency;
47 | fQuantity: integer;
48 | public
49 | property ID: integer read fID write fID;
50 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
51 | property ItemID: integer read fItemID write fItemID;
52 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
53 | property Quantity: Integer read fQuantity write fQuantity;
54 | end;
55 |
56 | TMainFormLabelsText = record
57 | Title,
58 | IssueButtonCaption,
59 | TotalSalesText,
60 | TotalSalesEmptyText: string;
61 | end;
62 |
63 |
64 |
65 | implementation
66 |
67 | end.
68 |
69 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~5~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | uses
6 | Model.ProSu.InterfaceActions, Model.ProSu.Interfaces;
7 |
8 | type
9 | TCustomer = class
10 | private
11 | fID: Integer;
12 | fName: string;
13 | fDiscountRate: Double;
14 | fBalance: Currency;
15 | public
16 | property ID: integer read fID write fID;
17 | property Name: string read fName write fName;
18 | property DiscountRate: double read fDiscountRate write fDiscountRate;
19 | property Balance: Currency read fBalance write fBalance;
20 | end;
21 |
22 | TItem = class
23 | private
24 | fID: Integer;
25 | fDescription: string;
26 | fPrice: Currency;
27 | public
28 | property ID: integer read fID write fID;
29 | property Description: string read fDescription write fDescription;
30 | property Price: Currency read fPrice write fPrice;
31 | end;
32 |
33 | TInvoice = class
34 | private
35 | fID: integer;
36 | fNumber: integer;
37 | public
38 | property ID: Integer read fID write fID;
39 | property Number: Integer read fNumber write fNumber;
40 | end;
41 |
42 | TInvoiceItem = class
43 | private
44 | fID: integer;
45 | fInvoiceID: integer;
46 | fItemID: integer;
47 | fUnitPrice: Currency;
48 | fQuantity: integer;
49 | public
50 | property ID: integer read fID write fID;
51 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
52 | property ItemID: integer read fItemID write fItemID;
53 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
54 | property Quantity: Integer read fQuantity write fQuantity;
55 | end;
56 |
57 | TMainFormLabelsText = record
58 | Title,
59 | IssueButtonCaption,
60 | TotalSalesText,
61 | TotalSalesEmptyText: string;
62 | end;
63 |
64 | TNotificationClass = class (TInterfacedObject, INotificationClass)
65 | action: TInterfaceActions;
66 | actionValue: Double;
67 | end;
68 |
69 |
70 | implementation
71 |
72 | end.
73 |
74 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~6~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | uses
6 | Model.ProSu.InterfaceActions, Model.ProSu.Interfaces;
7 |
8 | type
9 | TCustomer = class
10 | private
11 | fID: Integer;
12 | fName: string;
13 | fDiscountRate: Double;
14 | fBalance: Currency;
15 | public
16 | property ID: integer read fID write fID;
17 | property Name: string read fName write fName;
18 | property DiscountRate: double read fDiscountRate write fDiscountRate;
19 | property Balance: Currency read fBalance write fBalance;
20 | end;
21 |
22 | TItem = class
23 | private
24 | fID: Integer;
25 | fDescription: string;
26 | fPrice: Currency;
27 | public
28 | property ID: integer read fID write fID;
29 | property Description: string read fDescription write fDescription;
30 | property Price: Currency read fPrice write fPrice;
31 | end;
32 |
33 | TInvoice = class
34 | private
35 | fID: integer;
36 | fNumber: integer;
37 | public
38 | property ID: Integer read fID write fID;
39 | property Number: Integer read fNumber write fNumber;
40 | end;
41 |
42 | TInvoiceItem = class
43 | private
44 | fID: integer;
45 | fInvoiceID: integer;
46 | fItemID: integer;
47 | fUnitPrice: Currency;
48 | fQuantity: integer;
49 | public
50 | property ID: integer read fID write fID;
51 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
52 | property ItemID: integer read fItemID write fItemID;
53 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
54 | property Quantity: Integer read fQuantity write fQuantity;
55 | end;
56 |
57 | TMainFormLabelsText = record
58 | Title,
59 | IssueButtonCaption,
60 | TotalSalesText,
61 | TotalSalesEmptyText: string;
62 | end;
63 |
64 | TNotificationClass = class (TInterfacedObject, INotificationClass)
65 | private
66 | fActions: TInterfaceActions;
67 | fActionValue: Double;
68 | public
69 | property Actions: TInterfaceActions read fActions write fActions;
70 | property ActionValue: double read fActionValue write fActionValue;
71 | end;
72 |
73 |
74 | implementation
75 |
76 | end.
77 |
78 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~7~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | uses
6 | Model.ProSu.InterfaceActions, Model.ProSu.Interfaces;
7 |
8 | type
9 | TCustomer = class
10 | private
11 | fID: Integer;
12 | fName: string;
13 | fDiscountRate: Double;
14 | fBalance: Currency;
15 | public
16 | property ID: integer read fID write fID;
17 | property Name: string read fName write fName;
18 | property DiscountRate: double read fDiscountRate write fDiscountRate;
19 | property Balance: Currency read fBalance write fBalance;
20 | end;
21 |
22 | TItem = class
23 | private
24 | fID: Integer;
25 | fDescription: string;
26 | fPrice: Currency;
27 | public
28 | property ID: integer read fID write fID;
29 | property Description: string read fDescription write fDescription;
30 | property Price: Currency read fPrice write fPrice;
31 | end;
32 |
33 | TInvoice = class
34 | private
35 | fID: integer;
36 | fNumber: integer;
37 | public
38 | property ID: Integer read fID write fID;
39 | property Number: Integer read fNumber write fNumber;
40 | end;
41 |
42 | TInvoiceItem = class
43 | private
44 | fID: integer;
45 | fInvoiceID: integer;
46 | fItemID: integer;
47 | fUnitPrice: Currency;
48 | fQuantity: integer;
49 | public
50 | property ID: integer read fID write fID;
51 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
52 | property ItemID: integer read fItemID write fItemID;
53 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
54 | property Quantity: Integer read fQuantity write fQuantity;
55 | end;
56 |
57 | TMainFormLabelsText = record
58 | Title,
59 | IssueButtonCaption,
60 | TotalSalesText: string;
61 | end;
62 |
63 | TNotificationClass = class (TInterfacedObject, INotificationClass)
64 | private
65 | fActions: TInterfaceActions;
66 | fActionValue: Double;
67 | public
68 | property Actions: TInterfaceActions read fActions write fActions;
69 | property ActionValue: double read fActionValue write fActionValue;
70 | end;
71 |
72 |
73 | implementation
74 |
75 | end.
76 |
77 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Declarations.pas.~8~:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | public
35 | property ID: Integer read fID write fID;
36 | property Number: Integer read fNumber write fNumber;
37 | end;
38 |
39 | TInvoiceItem = class
40 | private
41 | fID: integer;
42 | fInvoiceID: integer;
43 | fItemID: integer;
44 | fUnitPrice: Currency;
45 | fQuantity: integer;
46 | public
47 | property ID: integer read fID write fID;
48 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
49 | property ItemID: integer read fItemID write fItemID;
50 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
51 | property Quantity: Integer read fQuantity write fQuantity;
52 | end;
53 |
54 | TMainFormLabelsText = record
55 | Title,
56 | IssueButtonCaption,
57 | TotalSalesText: string;
58 | end;
59 |
60 | implementation
61 |
62 | end.
63 |
64 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~1~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | implementation
6 |
7 | end.
8 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~2~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations;
6 |
7 | type
8 | TMainModel = class
9 | private
10 |
11 | end;
12 |
13 | implementation
14 |
15 | end.
16 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~3~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | public
12 | function GetMainFormLabelsText: TMainFormLabelsText;
13 | constructor Create;
14 | end;
15 |
16 | implementation
17 |
18 | { TMainModel }
19 |
20 | constructor TMainModel.Create;
21 | begin
22 | fMainFormLabelsText.Title:='';
23 | fMainFormLabelsText.IssueButtonCaption:='';
24 | fMainFormLabelsText.TotalSalesText:='';
25 | fMainFormLabelsText.TotalSalesEmptyText:='0';
26 | end;
27 |
28 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
29 | begin
30 | fMainFormLabelsText.Title:='Main Screen';
31 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
32 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
33 | fMainFormLabelsText.TotalSalesEmptyText:='0';
34 | end;
35 |
36 | end.
37 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~4~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | constructor Create;
15 | destructor Destroy; override;
16 | end;
17 |
18 | implementation
19 |
20 | uses
21 | System.SysUtils;
22 |
23 | { TMainModel }
24 |
25 | constructor TMainModel.Create;
26 | begin
27 | fMainFormLabelsText.Title:='';
28 | fMainFormLabelsText.IssueButtonCaption:='';
29 | fMainFormLabelsText.TotalSalesText:='';
30 | fMainFormLabelsText.TotalSalesEmptyText:='0';
31 |
32 | fDatabase:=TDatabase.Create;
33 | end;
34 |
35 | destructor TMainModel.Destroy;
36 | begin
37 | fDatabase.Free;
38 | inherited;
39 | end;
40 |
41 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
42 | begin
43 | fMainFormLabelsText.Title:='Main Screen';
44 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
45 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
46 | fMainFormLabelsText.TotalSalesEmptyText:=
47 | Format('%10.2f',[fDatabase.GetTotalSales]);
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~5~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | constructor Create;
15 | destructor Destroy; override;
16 | end;
17 |
18 | implementation
19 |
20 | uses
21 | System.SysUtils;
22 |
23 | { TMainModel }
24 |
25 | constructor TMainModel.Create;
26 | begin
27 | fMainFormLabelsText.Title:='';
28 | fMainFormLabelsText.IssueButtonCaption:='';
29 | fMainFormLabelsText.TotalSalesText:='';
30 | fMainFormLabelsText.TotalSalesEmptyText:='';
31 |
32 | fDatabase:=TDatabase.Create;
33 | end;
34 |
35 | destructor TMainModel.Destroy;
36 | begin
37 | fDatabase.Free;
38 | inherited;
39 | end;
40 |
41 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
42 | begin
43 | fMainFormLabelsText.Title:='Main Screen';
44 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
45 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
46 | fMainFormLabelsText.TotalSalesEmptyText:='0';
47 | end;
48 |
49 | end.
50 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~6~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fMainFormLabelsText.Title:='';
29 | fMainFormLabelsText.IssueButtonCaption:='';
30 | fMainFormLabelsText.TotalSalesText:='';
31 | fMainFormLabelsText.TotalSalesEmptyText:='';
32 |
33 | fDatabase:=TDatabase.Create;
34 | end;
35 |
36 | destructor TMainModel.Destroy;
37 | begin
38 | fDatabase.Free;
39 | inherited;
40 | end;
41 |
42 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
43 | begin
44 | fMainFormLabelsText.Title:='Main Screen';
45 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
46 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
47 | fMainFormLabelsText.TotalSalesEmptyText:='0';
48 | end;
49 |
50 | function TMainModel.GetTotalSales: Currency;
51 | begin
52 | result:=fDatabase.GetTotalSales;
53 | end;
54 |
55 | end.
56 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~7~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fMainFormLabelsText.Title:='';
29 | fMainFormLabelsText.IssueButtonCaption:='';
30 | fMainFormLabelsText.TotalSalesText:='';
31 | fMainFormLabelsText.TotalSalesEmptyText:='';
32 |
33 | fDatabase:=TDatabase.Create;
34 | end;
35 |
36 | destructor TMainModel.Destroy;
37 | begin
38 | fDatabase.Free;
39 | inherited;
40 | end;
41 |
42 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
43 | begin
44 | fMainFormLabelsText.Title:='Main Screen';
45 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
46 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
47 | fMainFormLabelsText.TotalSalesEmptyText:='0';
48 | result:=fMainFormLabelsText;
49 | end;
50 |
51 | function TMainModel.GetTotalSales: Currency;
52 | begin
53 | result:=fDatabase.GetTotalSales;
54 | end;
55 |
56 | end.
57 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Models/__history/Model.Main.pas.~8~:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fMainFormLabelsText.Title:='';
29 | fMainFormLabelsText.IssueButtonCaption:='';
30 | fMainFormLabelsText.TotalSalesText:='';
31 |
32 | fDatabase:=TDatabase.Create;
33 | end;
34 |
35 | destructor TMainModel.Destroy;
36 | begin
37 | fDatabase.Free;
38 | inherited;
39 | end;
40 |
41 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
42 | begin
43 | fMainFormLabelsText.Title:='Main Screen';
44 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
45 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
46 | result:=fMainFormLabelsText;
47 | end;
48 |
49 | function TMainModel.GetTotalSales: Currency;
50 | begin
51 | result:=fDatabase.GetTotalSales;
52 | end;
53 |
54 | end.
55 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/POSAppMVVM.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVM;
2 |
3 | uses
4 | EMemLeaks,
5 | EResLeaks,
6 | EDialogWinAPIMSClassic,
7 | EDialogWinAPIEurekaLogDetailed,
8 | EDialogWinAPIStepsToReproduce,
9 | EDebugExports,
10 | EDebugJCL,
11 | EFixSafeCallException,
12 | EMapWin32,
13 | EAppFMX,
14 | ExceptionLog7,
15 | System.StartUpCopy,
16 | FMX.Forms,
17 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
18 | Model.Database in 'Models\Model.Database.pas',
19 | Model.Declarations in 'Models\Model.Declarations.pas',
20 | Model.Main in 'Models\Model.Main.pas',
21 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas';
22 |
23 | {$R *.res}
24 |
25 | begin
26 | Application.Initialize;
27 | Application.CreateForm(TMainForm, MainForm);
28 | Application.Run;
29 | end.
30 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/POSAppMVVMProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {B3B485A6-155A-4CDB-9A42-C23416811A44}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | fLabelsText:=fModel.GetMainFormLabelsText;
30 | result:=fLabelsText;
31 | end;
32 |
33 | function TMainViewModel.GetTotalSalesValue: string;
34 | begin
35 | fTotalSalesValue:=fModel.GetTotalSales;
36 | result:=Format('%10.2f',[fTotalSalesValue]);
37 | end;
38 |
39 |
40 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
41 | begin
42 | fModel:=newModel;
43 | end;
44 |
45 | end.
46 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~10~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | destructor Destroy; override;
20 | end;
21 | implementation
22 |
23 | uses
24 | System.SysUtils;
25 |
26 | { TMainViewModel }
27 |
28 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
29 | begin
30 | if not Assigned(fModel) then
31 | begin
32 | fLabelsText.Title:='';
33 | fLabelsText.IssueButtonCaption:='';
34 | fLabelsText.TotalSalesText:='';
35 | end
36 | else
37 | fLabelsText:=fModel.GetMainFormLabelsText;
38 | result:=fLabelsText;
39 | end;
40 |
41 | function TMainViewModel.GetTotalSalesValue: string;
42 | begin
43 | if not Assigned(fModel) then
44 | fTotalSalesValue:=0.00
45 | else
46 | fTotalSalesValue:=fModel.GetTotalSales;
47 | result:=Format('%10.2f',[fTotalSalesValue]);
48 | end;
49 |
50 | destructor TMainViewModel.Destroy;
51 | begin
52 | fModel.Free;
53 | inherited;
54 | end;
55 |
56 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
57 | begin
58 | fModel:=newModel;
59 | end;
60 |
61 | end.
62 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~11~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | if not Assigned(fModel) then
30 | begin
31 | fLabelsText.Title:='';
32 | fLabelsText.IssueButtonCaption:='';
33 | fLabelsText.TotalSalesText:='';
34 | end
35 | else
36 | fLabelsText:=fModel.GetMainFormLabelsText;
37 | result:=fLabelsText;
38 | end;
39 |
40 | function TMainViewModel.GetTotalSalesValue: string;
41 | begin
42 | if not Assigned(fModel) then
43 | fTotalSalesValue:=0.00
44 | else
45 | fTotalSalesValue:=fModel.GetTotalSales;
46 | result:=Format('%10.2f',[fTotalSalesValue]);
47 | end;
48 |
49 |
50 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
51 | begin
52 | fModel:=newModel;
53 | end;
54 |
55 | end.
56 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~2~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | end.
23 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~3~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | { TMainViewModel }
23 |
24 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
25 | begin
26 |
27 | end;
28 |
29 | function TMainViewModel.GetTotalSalesValue: string;
30 | begin
31 |
32 | end;
33 |
34 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
35 | begin
36 |
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~4~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | if not Assigned(fModel) then
30 | begin
31 | fLabelsText.Title:='';
32 | fLabelsText.IssueButtonCaption:='';
33 | fLabelsText.TotalSalesText:='';
34 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',[0.00]);
35 | end
36 | else
37 | fLabelsText:=fModel.GetMainFormLabelsText;
38 | result:=fLabelsText;
39 | end;
40 |
41 | function TMainViewModel.GetTotalSalesValue: string;
42 | begin
43 | if not Assigned(fModel) then
44 | fTotalSalesValue:=0.00
45 | else
46 | fTotalSalesValue:=fModel.GetTotalSales;
47 | result:=Format('%10.2f',[fTotalSalesValue]);
48 | end;
49 |
50 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
51 | begin
52 |
53 | end;
54 |
55 | end.
56 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~5~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | if not Assigned(fModel) then
30 | begin
31 | fLabelsText.Title:='';
32 | fLabelsText.IssueButtonCaption:='';
33 | fLabelsText.TotalSalesText:='';
34 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',[0.00]);
35 | end
36 | else
37 | fLabelsText:=fModel.GetMainFormLabelsText;
38 | result:=fLabelsText;
39 | end;
40 |
41 | function TMainViewModel.GetTotalSalesValue: string;
42 | begin
43 | if not Assigned(fModel) then
44 | fTotalSalesValue:=0.00
45 | else
46 | fTotalSalesValue:=fModel.GetTotalSales;
47 | result:=Format('%10.2f',[fTotalSalesValue]);
48 | end;
49 |
50 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
51 | begin
52 | fModel:=newModel;
53 | end;
54 |
55 | end.
56 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~6~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | if not Assigned(fModel) then
30 | begin
31 | fLabelsText.Title:='';
32 | fLabelsText.IssueButtonCaption:='';
33 | fLabelsText.TotalSalesText:='';
34 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',[0.00]);
35 | end
36 | else
37 | begin
38 | fLabelsText:=fModel.GetMainFormLabelsText;
39 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',
40 | [StrToInt(fLabelsText.TotalSalesEmptyText)]);
41 | end;
42 | result:=fLabelsText;
43 | end;
44 |
45 | function TMainViewModel.GetTotalSalesValue: string;
46 | begin
47 | if not Assigned(fModel) then
48 | fTotalSalesValue:=0.00
49 | else
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
55 | begin
56 | fModel:=newModel;
57 | end;
58 |
59 | end.
60 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~7~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | destructor Destroy; override;
20 | end;
21 | implementation
22 |
23 | uses
24 | System.SysUtils;
25 |
26 | { TMainViewModel }
27 |
28 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
29 | begin
30 | if not Assigned(fModel) then
31 | begin
32 | fLabelsText.Title:='';
33 | fLabelsText.IssueButtonCaption:='';
34 | fLabelsText.TotalSalesText:='';
35 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',[0.00]);
36 | end
37 | else
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f', [0.00]);
41 | // [StrToInt(fLabelsText.TotalSalesEmptyText)]);
42 | end;
43 | result:=fLabelsText;
44 | end;
45 |
46 | function TMainViewModel.GetTotalSalesValue: string;
47 | begin
48 | if not Assigned(fModel) then
49 | fTotalSalesValue:=0.00
50 | else
51 | fTotalSalesValue:=fModel.GetTotalSales;
52 | result:=Format('%10.2f',[fTotalSalesValue]);
53 | end;
54 |
55 | destructor TMainViewModel.Destroy;
56 | begin
57 | fModel.Free;
58 | inherited;
59 | end;
60 |
61 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
62 | begin
63 | fModel:=newModel;
64 | end;
65 |
66 | end.
67 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~8~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | destructor Destroy; override;
20 | end;
21 | implementation
22 |
23 | uses
24 | System.SysUtils;
25 |
26 | { TMainViewModel }
27 |
28 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
29 | begin
30 | if not Assigned(fModel) then
31 | begin
32 | fLabelsText.Title:='';
33 | fLabelsText.IssueButtonCaption:='';
34 | fLabelsText.TotalSalesText:='';
35 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f',[0.00]);
36 | end
37 | else
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | fLabelsText.TotalSalesEmptyText:=Format('%10.2f', [0.00]);
41 | end;
42 | result:=fLabelsText;
43 | end;
44 |
45 | function TMainViewModel.GetTotalSalesValue: string;
46 | begin
47 | if not Assigned(fModel) then
48 | fTotalSalesValue:=0.00
49 | else
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 | destructor TMainViewModel.Destroy;
55 | begin
56 | fModel.Free;
57 | inherited;
58 | end;
59 |
60 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
61 | begin
62 | fModel:=newModel;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/ViewModels/__history/ViewModel.Main.pas.~9~:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | destructor Destroy; override;
20 | end;
21 | implementation
22 |
23 | uses
24 | System.SysUtils;
25 |
26 | { TMainViewModel }
27 |
28 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
29 | begin
30 | if not Assigned(fModel) then
31 | begin
32 | fLabelsText.Title:='';
33 | fLabelsText.IssueButtonCaption:='';
34 | fLabelsText.TotalSalesText:='';
35 | end
36 | else
37 | begin
38 | fLabelsText:=fModel.GetMainFormLabelsText;
39 | end;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetTotalSalesValue: string;
44 | begin
45 | if not Assigned(fModel) then
46 | fTotalSalesValue:=0.00
47 | else
48 | fTotalSalesValue:=fModel.GetTotalSales;
49 | result:=Format('%10.2f',[fTotalSalesValue]);
50 | end;
51 |
52 | destructor TMainViewModel.Destroy;
53 | begin
54 | fModel.Free;
55 | inherited;
56 | end;
57 |
58 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
59 | begin
60 | fModel:=newModel;
61 | end;
62 |
63 | end.
64 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/View.MainForm.pas:
--------------------------------------------------------------------------------
1 | unit View.MainForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8 | FMX.Controls.Presentation, ViewModel.Main, Model.Main;
9 |
10 | type
11 | TMainForm = class(TForm)
12 | LabelTitle: TLabel;
13 | ButtonInvoice: TButton;
14 | LabelTotalSalesText: TLabel;
15 | LabelTotalSalesFigure: TLabel;
16 | procedure FormCreate(Sender: TObject);
17 | procedure FormDestroy(Sender: TObject);
18 | private
19 | fMainModel: TMainModel;
20 | fViewModel: TMainViewModel;
21 | procedure SetViewModel (const newViewModel: TMainViewModel);
22 | procedure UpdateLabels;
23 | procedure UpdateTotalSalesFigure;
24 | public
25 | property ViewModel: TMainViewModel read fViewModel write SetViewModel;
26 | end;
27 |
28 | var
29 | MainForm: TMainForm;
30 |
31 | implementation
32 |
33 | {$R *.fmx}
34 |
35 |
36 | { TMainForm }
37 |
38 | procedure TMainForm.FormCreate(Sender: TObject);
39 | begin
40 | fmainModel:=TMainModel.Create;
41 | fViewModel:=TMainViewModel.Create;
42 | fViewModel.Model:=fmainModel;
43 | ViewModel:=fViewModel;
44 | end;
45 |
46 | procedure TMainForm.FormDestroy(Sender: TObject);
47 | begin
48 | fMainModel.Free;
49 | fViewModel.Free;
50 | end;
51 |
52 | procedure TMainForm.UpdateLabels;
53 | begin
54 | LabelTitle.Text := fViewModel.LabelsText.Title;
55 | LabelTotalSalesText.Text := fViewModel.LabelsText.TotalSalesText;
56 | LabelTotalSalesFigure.Text := fViewModel.GetTotalSalesValue;
57 | end;
58 |
59 | procedure TMainForm.UpdateTotalSalesFigure;
60 | begin
61 | ButtonInvoice.Text := fViewModel.LabelsText.IssueButtonCaption;
62 | end;
63 |
64 | procedure TMainForm.SetViewModel(const newViewModel: TMainViewModel);
65 | begin
66 | fViewModel:=newViewModel;
67 | UpdateLabels;
68 | UpdateTotalSalesFigure;
69 | end;
70 |
71 | end.
72 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.MainForm.fmx.~2~:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form3'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object LabelTitle: TLabel
12 | Align = Top
13 | StyledSettings = [Family, FontColor]
14 | Margins.Left = 20.000000000000000000
15 | Margins.Top = 20.000000000000000000
16 | Margins.Right = 20.000000000000000000
17 | Position.X = 20.000000000000000000
18 | Position.Y = 20.000000000000000000
19 | Size.Width = 320.000000000000000000
20 | Size.Height = 50.000000000000000000
21 | Size.PlatformDefault = False
22 | TextSettings.Font.Size = 24.000000000000000000
23 | TextSettings.Font.Style = [fsBold]
24 | TextSettings.HorzAlign = Center
25 | Text = 'Main Screen'
26 | end
27 | object ButtonInvoice: TButton
28 | Position.X = 96.000000000000000000
29 | Position.Y = 93.000000000000000000
30 | Size.Width = 167.000000000000000000
31 | Size.Height = 76.000000000000000000
32 | Size.PlatformDefault = False
33 | TabOrder = 0
34 | Text = 'Issue Invoice'
35 | end
36 | object LabelTotalSalesText: TLabel
37 | StyledSettings = [Family, FontColor]
38 | Position.X = 16.000000000000000000
39 | Position.Y = 200.000000000000000000
40 | Size.Width = 153.000000000000000000
41 | Size.Height = 25.000000000000000000
42 | Size.PlatformDefault = False
43 | TextSettings.Font.Size = 22.000000000000000000
44 | TextSettings.Font.Style = [fsBold]
45 | Text = 'Total Sales:'
46 | end
47 | object LabelTotalSalesFigure: TLabel
48 | StyledSettings = [Family]
49 | Position.X = 168.000000000000000000
50 | Position.Y = 200.000000000000000000
51 | Size.Width = 169.000000000000000000
52 | Size.Height = 25.000000000000000000
53 | Size.PlatformDefault = False
54 | TextSettings.Font.Size = 22.000000000000000000
55 | TextSettings.Font.Style = [fsBold]
56 | TextSettings.FontColor = claGreen
57 | TextSettings.HorzAlign = Trailing
58 | Text = '0'
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.MainForm.fmx.~3~:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form3'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object LabelTitle: TLabel
12 | Align = Top
13 | StyledSettings = [Family, FontColor]
14 | Margins.Left = 20.000000000000000000
15 | Margins.Top = 20.000000000000000000
16 | Margins.Right = 20.000000000000000000
17 | Position.X = 20.000000000000000000
18 | Position.Y = 20.000000000000000000
19 | Size.Width = 320.000000000000000000
20 | Size.Height = 50.000000000000000000
21 | Size.PlatformDefault = False
22 | TextSettings.Font.Size = 24.000000000000000000
23 | TextSettings.Font.Style = [fsBold]
24 | TextSettings.HorzAlign = Center
25 | Text = 'dummy_Title'
26 | end
27 | object ButtonInvoice: TButton
28 | Position.X = 96.000000000000000000
29 | Position.Y = 93.000000000000000000
30 | Size.Width = 167.000000000000000000
31 | Size.Height = 76.000000000000000000
32 | Size.PlatformDefault = False
33 | TabOrder = 0
34 | Text = 'dummy_IssueButton'
35 | end
36 | object LabelTotalSalesText: TLabel
37 | StyledSettings = [Family, FontColor]
38 | Position.X = 16.000000000000000000
39 | Position.Y = 200.000000000000000000
40 | Size.Width = 153.000000000000000000
41 | Size.Height = 25.000000000000000000
42 | Size.PlatformDefault = False
43 | TextSettings.Font.Size = 22.000000000000000000
44 | TextSettings.Font.Style = [fsBold]
45 | Text = 'dummy_TotalSales'
46 | end
47 | object LabelTotalSalesFigure: TLabel
48 | StyledSettings = [Family]
49 | Position.X = 168.000000000000000000
50 | Position.Y = 200.000000000000000000
51 | Size.Width = 169.000000000000000000
52 | Size.Height = 25.000000000000000000
53 | Size.PlatformDefault = False
54 | TextSettings.Font.Size = 22.000000000000000000
55 | TextSettings.Font.Style = [fsBold]
56 | TextSettings.FontColor = claGreen
57 | TextSettings.HorzAlign = Trailing
58 | Text = 'dummy_Sales'
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.MainForm.fmx.~4~:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object LabelTitle: TLabel
12 | Align = Top
13 | StyledSettings = [Family, FontColor]
14 | Margins.Left = 20.000000000000000000
15 | Margins.Top = 20.000000000000000000
16 | Margins.Right = 20.000000000000000000
17 | Position.X = 20.000000000000000000
18 | Position.Y = 20.000000000000000000
19 | Size.Width = 320.000000000000000000
20 | Size.Height = 50.000000000000000000
21 | Size.PlatformDefault = False
22 | TextSettings.Font.Size = 24.000000000000000000
23 | TextSettings.Font.Style = [fsBold]
24 | TextSettings.HorzAlign = Center
25 | Text = 'dummy_Title'
26 | end
27 | object ButtonInvoice: TButton
28 | Position.X = 96.000000000000000000
29 | Position.Y = 93.000000000000000000
30 | Size.Width = 167.000000000000000000
31 | Size.Height = 76.000000000000000000
32 | Size.PlatformDefault = False
33 | TabOrder = 0
34 | Text = 'dummy_IssueButton'
35 | end
36 | object LabelTotalSalesText: TLabel
37 | StyledSettings = [Family, FontColor]
38 | Position.X = 16.000000000000000000
39 | Position.Y = 200.000000000000000000
40 | Size.Width = 153.000000000000000000
41 | Size.Height = 25.000000000000000000
42 | Size.PlatformDefault = False
43 | TextSettings.Font.Size = 22.000000000000000000
44 | TextSettings.Font.Style = [fsBold]
45 | Text = 'dummy_TotalSales'
46 | end
47 | object LabelTotalSalesFigure: TLabel
48 | StyledSettings = [Family]
49 | Position.X = 168.000000000000000000
50 | Position.Y = 200.000000000000000000
51 | Size.Width = 169.000000000000000000
52 | Size.Height = 25.000000000000000000
53 | Size.PlatformDefault = False
54 | TextSettings.Font.Size = 22.000000000000000000
55 | TextSettings.Font.Style = [fsBold]
56 | TextSettings.FontColor = claGreen
57 | TextSettings.HorzAlign = Trailing
58 | Text = 'dummy_Sales'
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.MainForm.fmx.~5~:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'POSApp'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object LabelTitle: TLabel
12 | Align = Top
13 | StyledSettings = [Family, FontColor]
14 | Margins.Left = 20.000000000000000000
15 | Margins.Top = 20.000000000000000000
16 | Margins.Right = 20.000000000000000000
17 | Position.X = 20.000000000000000000
18 | Position.Y = 20.000000000000000000
19 | Size.Width = 320.000000000000000000
20 | Size.Height = 50.000000000000000000
21 | Size.PlatformDefault = False
22 | TextSettings.Font.Size = 24.000000000000000000
23 | TextSettings.Font.Style = [fsBold]
24 | TextSettings.HorzAlign = Center
25 | Text = 'dummy_Title'
26 | end
27 | object ButtonInvoice: TButton
28 | Position.X = 96.000000000000000000
29 | Position.Y = 93.000000000000000000
30 | Size.Width = 167.000000000000000000
31 | Size.Height = 76.000000000000000000
32 | Size.PlatformDefault = False
33 | TabOrder = 0
34 | Text = 'dummy_IssueButton'
35 | end
36 | object LabelTotalSalesText: TLabel
37 | StyledSettings = [Family, FontColor]
38 | Position.X = 16.000000000000000000
39 | Position.Y = 200.000000000000000000
40 | Size.Width = 153.000000000000000000
41 | Size.Height = 25.000000000000000000
42 | Size.PlatformDefault = False
43 | TextSettings.Font.Size = 22.000000000000000000
44 | TextSettings.Font.Style = [fsBold]
45 | Text = 'dummy_TotalSales'
46 | end
47 | object LabelTotalSalesFigure: TLabel
48 | StyledSettings = [Family]
49 | Position.X = 168.000000000000000000
50 | Position.Y = 200.000000000000000000
51 | Size.Width = 169.000000000000000000
52 | Size.Height = 25.000000000000000000
53 | Size.PlatformDefault = False
54 | TextSettings.Font.Size = 22.000000000000000000
55 | TextSettings.Font.Style = [fsBold]
56 | TextSettings.FontColor = claGreen
57 | TextSettings.HorzAlign = Trailing
58 | Text = 'dummy_Sales'
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.MainForm.pas.~18~:
--------------------------------------------------------------------------------
1 | unit View.MainForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8 | FMX.Controls.Presentation, ViewModel.Main, Model.Main;
9 |
10 | type
11 | TMainForm = class(TForm)
12 | LabelTitle: TLabel;
13 | ButtonInvoice: TButton;
14 | LabelTotalSalesText: TLabel;
15 | LabelTotalSalesFigure: TLabel;
16 | procedure FormCreate(Sender: TObject);
17 | procedure FormDestroy(Sender: TObject);
18 | private
19 | fMainModel: TMainModel;
20 | fViewModel: TMainViewModel;
21 | procedure SetViewModel (const newViewModel: TMainViewModel);
22 | procedure UpdateLabels;
23 | procedure UpdateTotalSalesFigure;
24 | public
25 | property ViewModel: TMainViewModel read fViewModel write SetViewModel;
26 | end;
27 |
28 | var
29 | MainForm: TMainForm;
30 |
31 | implementation
32 |
33 | {$R *.fmx}
34 |
35 |
36 | { TMainForm }
37 |
38 | procedure TMainForm.FormCreate(Sender: TObject);
39 | begin
40 | fmainModel:=TMainModel.Create;
41 | fViewModel:=TMainViewModel.Create;
42 | fViewModel.Model:=fmainModel;
43 | ViewModel:=fViewModel;
44 | end;
45 |
46 | procedure TMainForm.FormDestroy(Sender: TObject);
47 | begin
48 | fMainModel.Free;
49 | fViewModel.Free;
50 | end;
51 |
52 | procedure TMainForm.UpdateLabels;
53 | begin
54 | if not Assigned(fViewModel) then
55 | Exit;
56 | LabelTitle.Text := fViewModel.LabelsText.Title;
57 | LabelTotalSalesText.Text := fViewModel.LabelsText.TotalSalesText;
58 | LabelTotalSalesFigure.Text := fViewModel.GetTotalSalesValue;
59 | end;
60 |
61 | procedure TMainForm.UpdateTotalSalesFigure;
62 | begin
63 | if not Assigned(fViewModel) then
64 | Exit;
65 | ButtonInvoice.Text := fViewModel.LabelsText.IssueButtonCaption;
66 | end;
67 |
68 | procedure TMainForm.SetViewModel(const newViewModel: TMainViewModel);
69 | begin
70 | fViewModel:=newViewModel;
71 | if not Assigned(fViewModel) then
72 | Exit;
73 | UpdateLabels;
74 | UpdateTotalSalesFigure;
75 | end;
76 |
77 | end.
78 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.fmx.~1~:
--------------------------------------------------------------------------------
1 | object Form1: TForm1
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 345
6 | ClientWidth = 538
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | end
12 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.fmx.~2~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 108
6 | ClientWidth = 276
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object ButtonPrintInvoice: TButton
12 | Position.X = 40.000000000000000000
13 | Position.Y = 24.000000000000000000
14 | Size.Width = 193.000000000000000000
15 | Size.Height = 49.000000000000000000
16 | Size.PlatformDefault = False
17 | TabOrder = 1
18 | Text = 'Print Invoice'
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.fmx.~3~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 108
6 | ClientWidth = 276
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 24.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 49.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.fmx.~4~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 108
6 | ClientWidth = 276
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 24.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 49.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.fmx.~5~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 108
6 | ClientWidth = 276
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 24.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 49.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | OnClick = ButtonPrintInvoiceClick
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~1~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
8 |
9 | type
10 | TForm1 = class(TForm)
11 | private
12 | { Private declarations }
13 | public
14 | { Public declarations }
15 | end;
16 |
17 | var
18 | Form1: TForm1;
19 |
20 | implementation
21 |
22 | {$R *.fmx}
23 |
24 | end.
25 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~2~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls;
9 |
10 | type
11 | TTestPrintInvoiceForm = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | private
14 | { Private declarations }
15 | public
16 | { Public declarations }
17 | end;
18 |
19 | var
20 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
21 |
22 | implementation
23 |
24 | {$R *.fmx}
25 |
26 | end.
27 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~3~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces;
9 |
10 | type
11 | TTestPrintInvoiceForm = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | procedure FormCreate(Sender: TObject);
14 | private
15 | fProvider: IProviderInterface;
16 | public
17 | { Public declarations }
18 | end;
19 |
20 | var
21 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
22 |
23 | implementation
24 |
25 | {$R *.fmx}
26 |
27 | uses Model.ProSu.Provider;
28 |
29 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
30 | begin
31 | fProvider:=TProSuProvider.Create;
32 | end;
33 |
34 | end.
35 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~4~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces;
9 |
10 | type
11 | TTestPrintInvoiceForm = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | procedure FormCreate(Sender: TObject);
14 | private
15 | fProvider: IProviderInterface;
16 | public
17 | { Public declarations }
18 | end;
19 |
20 | var
21 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
22 |
23 | implementation
24 |
25 | {$R *.fmx}
26 |
27 | uses Model.ProSu.Provider;
28 |
29 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
30 | begin
31 | fProvider:=TProSuProvider.Create;
32 | end;
33 |
34 | end.
35 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~5~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces;
9 |
10 | type
11 | TTestPrintInvoiceForm = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | procedure FormCreate(Sender: TObject);
14 | procedure ButtonPrintInvoiceClick(Sender: TObject);
15 | private
16 | fProvider: IProviderInterface;
17 | public
18 | { Public declarations }
19 | end;
20 |
21 | var
22 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
23 |
24 | implementation
25 |
26 | {$R *.fmx}
27 |
28 | uses Model.ProSu.Provider, Model.Declarations, Model.ProSu.InterfaceActions;
29 |
30 | procedure TTestPrintInvoiceForm.ButtonPrintInvoiceClick(Sender: TObject);
31 | var
32 | tmpNotificationClass: TNotificationClass;
33 | begin
34 | tmpNotificationClass:=TNotificationClass.Create;
35 | tmpNotificationClass.Actions:=[UpdateTotalSalesFigure];
36 | tmpNotificationClass.ActionValue:=random(1300);
37 | if Assigned(fProvider) then
38 | fProvider.NotifySubscribers(tmpNotificationClass);
39 | end;
40 |
41 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
42 | begin
43 | fProvider:=TProSuProvider.Create;
44 | end;
45 |
46 | end.
47 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVM/Views/__history/View.TestPrintInvoice.pas.~6~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces;
9 |
10 | type
11 | TTestPrintInvoiceForm = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | procedure FormCreate(Sender: TObject);
14 | procedure ButtonPrintInvoiceClick(Sender: TObject);
15 | private
16 | fProvider: IProviderInterface;
17 | public
18 | property Provider: IProviderInterface read fProvider;
19 | end;
20 |
21 | var
22 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
23 |
24 | implementation
25 |
26 | {$R *.fmx}
27 |
28 | uses Model.ProSu.Provider, Model.Declarations, Model.ProSu.InterfaceActions;
29 |
30 | procedure TTestPrintInvoiceForm.ButtonPrintInvoiceClick(Sender: TObject);
31 | var
32 | tmpNotificationClass: TNotificationClass;
33 | begin
34 | tmpNotificationClass:=TNotificationClass.Create;
35 | tmpNotificationClass.Actions:=[UpdateTotalSalesFigure];
36 | tmpNotificationClass.ActionValue:=random(1300);
37 | if Assigned(fProvider) then
38 | fProvider.NotifySubscribers(tmpNotificationClass);
39 | end;
40 |
41 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
42 | begin
43 | fProvider:=TProSuProvider.Create;
44 | end;
45 |
46 | end.
47 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/Models/Model.Declarations.pas:
--------------------------------------------------------------------------------
1 | unit Model.Declarations;
2 |
3 | interface
4 |
5 | type
6 | TCustomer = class
7 | private
8 | fID: Integer;
9 | fName: string;
10 | fDiscountRate: Double;
11 | fBalance: Currency;
12 | public
13 | property ID: integer read fID write fID;
14 | property Name: string read fName write fName;
15 | property DiscountRate: double read fDiscountRate write fDiscountRate;
16 | property Balance: Currency read fBalance write fBalance;
17 | end;
18 |
19 | TItem = class
20 | private
21 | fID: Integer;
22 | fDescription: string;
23 | fPrice: Currency;
24 | public
25 | property ID: integer read fID write fID;
26 | property Description: string read fDescription write fDescription;
27 | property Price: Currency read fPrice write fPrice;
28 | end;
29 |
30 | TInvoice = class
31 | private
32 | fID: integer;
33 | fNumber: integer;
34 | fCustomerID: integer;
35 | public
36 | property ID: Integer read fID write fID;
37 | property Number: Integer read fNumber write fNumber;
38 | property CustomerID: integer read fCustomerID write fCustomerID;
39 | end;
40 |
41 | TInvoiceItem = class
42 | private
43 | fID: integer;
44 | fInvoiceID: integer;
45 | fItemID: integer;
46 | fUnitPrice: Currency;
47 | fQuantity: integer;
48 | public
49 | property ID: integer read fID write fID;
50 | property InvoiceID: integer read fInvoiceID write fInvoiceID;
51 | property ItemID: integer read fItemID write fItemID;
52 | property UnitPrice: Currency read fUnitPrice write fUnitPrice;
53 | property Quantity: Integer read fQuantity write fQuantity;
54 | end;
55 |
56 | TMainFormLabelsText = record
57 | Title,
58 | IssueButtonCaption,
59 | TotalSalesText: string;
60 | end;
61 |
62 | implementation
63 |
64 | end.
65 |
66 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fDatabase:=TDatabase.Create;
29 | end;
30 |
31 | destructor TMainModel.Destroy;
32 | begin
33 | fDatabase.Free;
34 | inherited;
35 | end;
36 |
37 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
38 | begin
39 | fMainFormLabelsText.Title:='Main Screen';
40 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
41 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
42 | result:=fMainFormLabelsText;
43 | end;
44 |
45 | function TMainModel.GetTotalSales: Currency;
46 | begin
47 | result:=fDatabase.GetTotalSales;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/POSAppMVVMMainForm.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMMainForm;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Declarations in 'Models\Model.Declarations.pas',
10 | Model.Main in 'Models\Model.Main.pas';
11 |
12 | {$R *.res}
13 |
14 | var
15 | mainModel: TMainModel;
16 | mainViewModel: TMainViewModel;
17 |
18 | begin
19 | mainModel:=TMainModel.Create;
20 | mainViewModel:=TMainViewModel.Create;
21 | mainViewModel.Model:=mainModel;
22 |
23 | Application.Initialize;
24 |
25 | MainForm:=TMainForm.Create(Application);
26 | MainForm.ViewModel:=mainViewModel;
27 |
28 | Application.MainForm:=MainForm;
29 | MainForm.Show;
30 | Application.Run;
31 |
32 | end.
33 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/POSAppMVVMMainForm.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 3/POSAppMVVMMainForm/POSAppMVVMMainForm.res
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/POSAppMVVMMainFormProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {B3B485A6-155A-4CDB-9A42-C23416811A44}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | fLabelsText:=fModel.GetMainFormLabelsText;
30 | result:=fLabelsText;
31 | end;
32 |
33 | function TMainViewModel.GetTotalSalesValue: string;
34 | begin
35 | fTotalSalesValue:=fModel.GetTotalSales;
36 | result:=Format('%10.2f',[fTotalSalesValue]);
37 | end;
38 |
39 |
40 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
41 | begin
42 | fModel:=newModel;
43 | end;
44 |
45 | end.
46 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/Views/View.MainForm.fmx:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'POSApp'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnDestroy = FormDestroy
11 | DesignerMasterStyle = 0
12 | object LabelTitle: TLabel
13 | Align = Top
14 | StyledSettings = [Family, FontColor]
15 | Margins.Left = 20.000000000000000000
16 | Margins.Top = 20.000000000000000000
17 | Margins.Right = 20.000000000000000000
18 | Position.X = 20.000000000000000000
19 | Position.Y = 20.000000000000000000
20 | Size.Width = 320.000000000000000000
21 | Size.Height = 50.000000000000000000
22 | Size.PlatformDefault = False
23 | TextSettings.Font.Size = 24.000000000000000000
24 | TextSettings.Font.Style = [fsBold]
25 | TextSettings.HorzAlign = Center
26 | Text = 'dummy_Title'
27 | end
28 | object ButtonInvoice: TButton
29 | Position.X = 96.000000000000000000
30 | Position.Y = 93.000000000000000000
31 | Size.Width = 167.000000000000000000
32 | Size.Height = 76.000000000000000000
33 | Size.PlatformDefault = False
34 | TabOrder = 0
35 | Text = 'dummy_IssueButton'
36 | end
37 | object LabelTotalSalesText: TLabel
38 | StyledSettings = [Family, FontColor]
39 | Position.X = 16.000000000000000000
40 | Position.Y = 200.000000000000000000
41 | Size.Width = 153.000000000000000000
42 | Size.Height = 25.000000000000000000
43 | Size.PlatformDefault = False
44 | TextSettings.Font.Size = 22.000000000000000000
45 | TextSettings.Font.Style = [fsBold]
46 | Text = 'dummy_TotalSales'
47 | end
48 | object LabelTotalSalesFigure: TLabel
49 | StyledSettings = [Family]
50 | Position.X = 168.000000000000000000
51 | Position.Y = 200.000000000000000000
52 | Size.Width = 169.000000000000000000
53 | Size.Height = 25.000000000000000000
54 | Size.PlatformDefault = False
55 | TextSettings.Font.Size = 22.000000000000000000
56 | TextSettings.Font.Style = [fsBold]
57 | TextSettings.FontColor = claGreen
58 | TextSettings.HorzAlign = Trailing
59 | Text = 'dummy_Sales'
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/Chapter 3/POSAppMVVMMainForm/Views/View.MainForm.pas:
--------------------------------------------------------------------------------
1 | unit View.MainForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8 | FMX.Controls.Presentation, ViewModel.Main, Model.Main;
9 |
10 | type
11 | TMainForm = class(TForm)
12 | LabelTitle: TLabel;
13 | ButtonInvoice: TButton;
14 | LabelTotalSalesText: TLabel;
15 | LabelTotalSalesFigure: TLabel;
16 | procedure FormDestroy(Sender: TObject);
17 | private
18 | fViewModel: TMainViewModel;
19 | procedure SetViewModel (const newViewModel: TMainViewModel);
20 | procedure UpdateLabels;
21 | procedure UpdateTotalSalesFigure;
22 | public
23 | property ViewModel: TMainViewModel read fViewModel write SetViewModel;
24 | end;
25 |
26 | var
27 | MainForm: TMainForm;
28 |
29 | implementation
30 |
31 | {$R *.fmx}
32 |
33 |
34 | { TMainForm }
35 |
36 | procedure TMainForm.FormDestroy(Sender: TObject);
37 | begin
38 | fViewModel.Model.Free;
39 | fViewModel.Free;
40 | end;
41 |
42 | procedure TMainForm.UpdateLabels;
43 | begin
44 | LabelTitle.Text := fViewModel.LabelsText.Title;
45 | LabelTotalSalesText.Text := fViewModel.LabelsText.TotalSalesText;
46 | LabelTotalSalesFigure.Text := fViewModel.GetTotalSalesValue;
47 | end;
48 |
49 | procedure TMainForm.UpdateTotalSalesFigure;
50 | begin
51 | ButtonInvoice.Text := fViewModel.LabelsText.IssueButtonCaption;
52 | end;
53 |
54 | procedure TMainForm.SetViewModel(const newViewModel: TMainViewModel);
55 | begin
56 | fViewModel:=newViewModel;
57 | if not Assigned(fViewModel) then
58 | raise Exception.Create('Main View Model is required');
59 | UpdateLabels;
60 | UpdateTotalSalesFigure;
61 | end;
62 |
63 | end.
64 |
--------------------------------------------------------------------------------
/Chapter 3/Thin Forms/View.MainForm.fmx:
--------------------------------------------------------------------------------
1 | object MainForm: TMainForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'POSApp'
5 | ClientHeight = 260
6 | ClientWidth = 360
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object LabelTitle: TLabel
12 | Align = Top
13 | StyledSettings = [Family, FontColor]
14 | Margins.Left = 20.000000000000000000
15 | Margins.Top = 20.000000000000000000
16 | Margins.Right = 20.000000000000000000
17 | Position.X = 20.000000000000000000
18 | Position.Y = 20.000000000000000000
19 | Size.Width = 320.000000000000000000
20 | Size.Height = 50.000000000000000000
21 | Size.PlatformDefault = False
22 | TextSettings.Font.Size = 24.000000000000000000
23 | TextSettings.Font.Style = [fsBold]
24 | TextSettings.HorzAlign = Center
25 | Text = 'dummy_Title'
26 | end
27 | object ButtonInvoice: TButton
28 | Position.X = 96.000000000000000000
29 | Position.Y = 93.000000000000000000
30 | Size.Width = 167.000000000000000000
31 | Size.Height = 76.000000000000000000
32 | Size.PlatformDefault = False
33 | TabOrder = 0
34 | Text = 'dummy_IssueButton'
35 | end
36 | object LabelTotalSalesText: TLabel
37 | StyledSettings = [Family, FontColor]
38 | Position.X = 16.000000000000000000
39 | Position.Y = 200.000000000000000000
40 | Size.Width = 153.000000000000000000
41 | Size.Height = 25.000000000000000000
42 | Size.PlatformDefault = False
43 | TextSettings.Font.Size = 22.000000000000000000
44 | TextSettings.Font.Style = [fsBold]
45 | Text = 'dummy_TotalSales'
46 | end
47 | object LabelTotalSalesFigure: TLabel
48 | StyledSettings = [Family]
49 | Position.X = 168.000000000000000000
50 | Position.Y = 200.000000000000000000
51 | Size.Width = 169.000000000000000000
52 | Size.Height = 25.000000000000000000
53 | Size.PlatformDefault = False
54 | TextSettings.Font.Size = 22.000000000000000000
55 | TextSettings.Font.Style = [fsBold]
56 | TextSettings.FontColor = claGreen
57 | TextSettings.HorzAlign = Trailing
58 | Text = 'dummy_Sales'
59 | end
60 | end
61 |
--------------------------------------------------------------------------------
/Chapter 3/Thin Forms/View.MainForm.pas:
--------------------------------------------------------------------------------
1 | unit View.MainForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8 | FMX.Controls.Presentation;
9 |
10 | type
11 | TMainForm = class(TForm)
12 | LabelTitle: TLabel;
13 | ButtonInvoice: TButton;
14 | LabelTotalSalesText: TLabel;
15 | LabelTotalSalesFigure: TLabel;
16 | private
17 | { Private declarations }
18 | public
19 | { Public declarations }
20 | end;
21 |
22 | var
23 | MainForm: TMainForm;
24 |
25 | implementation
26 |
27 | {$R *.fmx}
28 |
29 | end.
30 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/Models/Model.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.Interfaces;
2 |
3 | interface
4 |
5 | uses
6 | Model.Declarations, System.Generics.Collections;
7 |
8 | type
9 | IDatabaseInterface = interface
10 | ['{DDE3E13A-0EC5-4712-B068-9B510977CF71}']
11 | function GetCustomerList: TObjectList;
12 | function GetCustomerFromName(const nameStr: string): TCustomer;
13 | function GetItems: TObjectList;
14 | function GetItemFromDescription(const desc: string): TItem;
15 | function GetItemFromID(const id: Integer): TItem;
16 | function GetTotalSales: Currency;
17 | procedure SaveCurrentSales(const currentSales: Currency);
18 | end;
19 |
20 | IMainModelInterface = interface
21 | ['{1345E22D-6229-4C27-8D08-6EA8584BE718}']
22 | function GetMainFormLabelsText: TMainFormLabelsText;
23 | function GetTotalSales: Currency;
24 | end;
25 |
26 | IMainViewModelInterface = interface
27 | ['{62CF0DAC-C808-4B1A-A6DC-57D7DC1912CB}']
28 | function GetModel: IMainModelInterface;
29 | procedure SetModel (const newModel: IMainModelInterface);
30 | function GetLabelsText: TMainFormLabelsText;
31 | function GetTotalSalesValue: string;
32 | property Model: IMainModelInterface read GetModel write SetModel;
33 | property LabelsText: TMainFormLabelsText read GetlabelsText;
34 | end;
35 |
36 | implementation
37 |
38 | end.
39 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fDatabase:=CreateDatabaseClass;
36 | end;
37 |
38 |
39 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
40 | begin
41 | fMainFormLabelsText.Title:='Main Screen';
42 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
43 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
44 | result:=fMainFormLabelsText;
45 | end;
46 |
47 | function TMainModel.GetTotalSales: Currency;
48 | begin
49 | result:=fDatabase.GetTotalSales;
50 | end;
51 |
52 | end.
53 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMMainFormFullInterfaces;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas';
16 |
17 | {$R *.res}
18 |
19 | var
20 | mainModel: IMainModelInterface;
21 | mainViewModel: IMainViewModelInterface;
22 |
23 | begin
24 | mainModel:=CreateMainModelClass;
25 | mainViewModel:=CreateMainViewModelClass;
26 | mainViewModel.Model:=mainModel;
27 |
28 | Application.Initialize;
29 |
30 | MainForm:=TMainForm.Create(Application);
31 | MainForm.ViewModel:=mainViewModel;
32 |
33 | Application.MainForm:=MainForm;
34 | MainForm.Show;
35 | Application.Run;
36 |
37 | end.
38 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 4/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.res
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 |
26 | implementation
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormFullInterfaces/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fDatabase:=TDatabase.Create;
29 | end;
30 |
31 | destructor TMainModel.Destroy;
32 | begin
33 | fDatabase.Free;
34 | inherited;
35 | end;
36 |
37 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
38 | begin
39 | fMainFormLabelsText.Title:='Main Screen';
40 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
41 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
42 | result:=fMainFormLabelsText;
43 | end;
44 |
45 | function TMainModel.GetTotalSales: Currency;
46 | begin
47 | result:=fDatabase.GetTotalSales;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/POSAppMVVMMainFormInterfaces.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMMainFormInterfaces;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas';
15 |
16 | {$R *.res}
17 |
18 | var
19 | mainModel: TMainModel;
20 | mainViewModel: TMainViewModel;
21 |
22 | begin
23 | mainModel:=TMainModel.Create;
24 | mainViewModel:=TMainViewModel.Create;
25 | mainViewModel.Model:=mainModel;
26 |
27 | Application.Initialize;
28 |
29 | MainForm:=TMainForm.Create(Application);
30 | MainForm.ViewModel:=mainViewModel;
31 |
32 | Application.MainForm:=MainForm;
33 | MainForm.Show;
34 | Application.Run;
35 |
36 | end.
37 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/POSAppMVVMMainFormInterfaces.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 4/POSAppMVVMMainFormInterfaces/POSAppMVVMMainFormInterfaces.res
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/POSAppMVVMMainFormInterfacesProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {B3B485A6-155A-4CDB-9A42-C23416811A44}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 | implementation
26 |
27 | end.
28 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | type
8 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
9 | private
10 | fSubscriberList: TList;
11 | public
12 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
13 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
14 | procedure NotifySubscribers (const notifyClass: INotificationClass);
15 |
16 | constructor Create;
17 | destructor Destroy; override;
18 | end;
19 |
20 | implementation
21 |
22 | { TProSuProvider }
23 |
24 | constructor TProSuProvider.Create;
25 | begin
26 | inherited;
27 | fSubscriberList:=TList.Create;
28 | end;
29 |
30 | destructor TProSuProvider.Destroy;
31 | var
32 | iTemp: ISubscriberInterface;
33 | begin
34 | for itemp in fSubscriberList do
35 | Unsubscribe(iTemp);
36 | fSubscriberList.Free;
37 | inherited;
38 | end;
39 |
40 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
41 | var
42 | tmpSubscriber: ISubscriberInterface;
43 | begin
44 | for tmpSubscriber in fSubscriberList do
45 | tmpSubscriber.UpdateSubscriber(notifyClass);
46 | end;
47 |
48 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
49 | begin
50 | fSubscriberList.Add(tmpSubscriber);
51 | end;
52 |
53 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
54 | begin
55 | fSubscriberList.Remove(tmpSubscriber);
56 | end;
57 |
58 | end.
59 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | type
8 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
9 | private
10 | fUpdateMethod: TUpdateSubscriberMethod;
11 | public
12 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
13 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
14 | end;
15 |
16 | implementation
17 |
18 | { TProSuSubscriber }
19 |
20 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
21 | newMethod: TUpdateSubscriberMethod);
22 | begin
23 | fUpdateMethod:=newMethod;
24 | end;
25 |
26 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
27 | begin
28 | if Assigned(fUpdateMethod) then
29 | fUpdateMethod(notifyClass);
30 | end;
31 |
32 | end.
33 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | fLabelsText:=fModel.GetMainFormLabelsText;
30 | result:=fLabelsText;
31 | end;
32 |
33 | function TMainViewModel.GetTotalSalesValue: string;
34 | begin
35 | fTotalSalesValue:=fModel.GetTotalSales;
36 | result:=Format('%10.2f',[fTotalSalesValue]);
37 | end;
38 |
39 |
40 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
41 | begin
42 | fModel:=newModel;
43 | end;
44 |
45 | end.
46 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/Views/View.TestPrintInvoice.fmx:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Test Print Invoice'
5 | ClientHeight = 144
6 | ClientWidth = 274
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 32.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 65.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | OnClick = ButtonPrintInvoiceClick
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormInterfaces/Views/View.TestPrintInvoice.pas:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces,
9 | Model.ProSu.Provider;
10 |
11 | type
12 | TTestPrintInvoiceForm = class(TForm)
13 | ButtonPrintInvoice: TButton;
14 | procedure FormCreate(Sender: TObject);
15 | procedure ButtonPrintInvoiceClick(Sender: TObject);
16 | private
17 | fProvider: IProviderInterface;
18 | public
19 | property Provider: IProviderInterface read fProvider;
20 | end;
21 |
22 | var
23 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
24 |
25 | implementation
26 |
27 | uses
28 | Model.Declarations, Model.ProSu.InterfaceActions;
29 | {$R *.fmx}
30 |
31 | procedure TTestPrintInvoiceForm.ButtonPrintInvoiceClick(Sender: TObject);
32 | var
33 | tmpNotificationClass: TNotificationClass;
34 | begin
35 | tmpNotificationClass:=TNotificationClass.Create;
36 | try
37 | tmpNotificationClass.Actions:=[actUpdateTotalSalesFigure];
38 | tmpNotificationClass.ActionValue:=Random(1300);
39 | fProvider.NotifySubscribers(tmpNotificationClass);
40 | finally
41 | tmpNotificationClass.Free;
42 | end;
43 | end;
44 |
45 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
46 | begin
47 | fProvider:=TProSuProvider.Create;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database;
6 |
7 | type
8 | TMainModel = class
9 | private
10 | fMainFormLabelsText: TMainFormLabelsText;
11 | fDatabase: TDatabase;
12 | public
13 | function GetMainFormLabelsText: TMainFormLabelsText;
14 | function GetTotalSales: Currency;
15 | constructor Create;
16 | destructor Destroy; override;
17 | end;
18 |
19 | implementation
20 |
21 | uses
22 | System.SysUtils;
23 |
24 | { TMainModel }
25 |
26 | constructor TMainModel.Create;
27 | begin
28 | fDatabase:=TDatabase.Create;
29 | end;
30 |
31 | destructor TMainModel.Destroy;
32 | begin
33 | fDatabase.Free;
34 | inherited;
35 | end;
36 |
37 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
38 | begin
39 | fMainFormLabelsText.Title:='Main Screen';
40 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
41 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
42 | result:=fMainFormLabelsText;
43 | end;
44 |
45 | function TMainModel.GetTotalSales: Currency;
46 | begin
47 | result:=fDatabase.GetTotalSales;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/POSAppMVVMMainFormTest.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMMainFormTest;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | View.TestPrintInvoice in 'Views\View.TestPrintInvoice.pas' {TestPrintInvoiceForm},
14 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
15 | Model.Declarations in 'Models\Model.Declarations.pas';
16 |
17 | {$R *.res}
18 |
19 | var
20 | mainModel: TMainModel;
21 | mainViewModel: TMainViewModel;
22 |
23 | begin
24 | mainModel:=TMainModel.Create;
25 | mainViewModel:=TMainViewModel.Create;
26 | mainViewModel.Model:=mainModel;
27 |
28 | Application.Initialize;
29 |
30 | MainForm:=TMainForm.Create(Application);
31 | MainForm.ViewModel:=mainViewModel;
32 |
33 | Application.MainForm:=MainForm;
34 | MainForm.Show;
35 | Application.CreateForm(TTestPrintInvoiceForm, TestPrintInvoiceForm);
36 | Application.Run;
37 |
38 | end.
39 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/POSAppMVVMMainFormTest.stat:
--------------------------------------------------------------------------------
1 | [Stats]
2 | EditorSecs=1655
3 | DesignerSecs=1
4 | InspectorSecs=108
5 | CompileSecs=212255
6 | OtherSecs=468
7 | StartTime=31/07/2016 21:39:46
8 | RealKeys=0
9 | EffectiveKeys=0
10 | DebugSecs=210
11 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/POSAppMVVMMainFormTestProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {B3B485A6-155A-4CDB-9A42-C23416811A44}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 | implementation
26 |
27 | end.
28 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | type
8 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
9 | private
10 | fSubscriberList: TList;
11 | public
12 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
13 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
14 | procedure NotifySubscribers (const notifyClass: INotificationClass);
15 |
16 | constructor Create;
17 | destructor Destroy; override;
18 | end;
19 |
20 | implementation
21 |
22 | { TProSuProvider }
23 |
24 | constructor TProSuProvider.Create;
25 | begin
26 | inherited;
27 | fSubscriberList:=TList.Create;
28 | end;
29 |
30 | destructor TProSuProvider.Destroy;
31 | var
32 | iTemp: ISubscriberInterface;
33 | begin
34 | for itemp in fSubscriberList do
35 | Unsubscribe(iTemp);
36 | fSubscriberList.Free;
37 | inherited;
38 | end;
39 |
40 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
41 | var
42 | tmpSubscriber: ISubscriberInterface;
43 | begin
44 | for tmpSubscriber in fSubscriberList do
45 | tmpSubscriber.UpdateSubscriber(notifyClass);
46 | end;
47 |
48 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
49 | begin
50 | fSubscriberList.Add(tmpSubscriber);
51 | end;
52 |
53 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
54 | begin
55 | fSubscriberList.Remove(tmpSubscriber);
56 | end;
57 |
58 | end.
59 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | type
8 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
9 | private
10 | fUpdateMethod: TUpdateSubscriberMethod;
11 | public
12 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
13 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
14 | end;
15 |
16 | implementation
17 |
18 | { TProSuSubscriber }
19 |
20 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
21 | newMethod: TUpdateSubscriberMethod);
22 | begin
23 | fUpdateMethod:=newMethod;
24 | end;
25 |
26 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
27 | begin
28 | if Assigned(fUpdateMethod) then
29 | fUpdateMethod(notifyClass);
30 | end;
31 |
32 | end.
33 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations;
6 |
7 | type
8 | TMainViewModel = class
9 | private
10 | fModel: TMainModel;
11 | fLabelsText: TMainFormLabelsText;
12 | fTotalSalesValue: Currency;
13 | procedure SetModel (const newModel: TMainModel);
14 | function GetLabelsText: TMainFormLabelsText;
15 | public
16 | property Model: TMainModel read fModel write SetModel;
17 | property LabelsText: TMainFormLabelsText read GetlabelsText;
18 | function GetTotalSalesValue: string;
19 | end;
20 | implementation
21 |
22 | uses
23 | System.SysUtils;
24 |
25 | { TMainViewModel }
26 |
27 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
28 | begin
29 | fLabelsText:=fModel.GetMainFormLabelsText;
30 | result:=fLabelsText;
31 | end;
32 |
33 | function TMainViewModel.GetTotalSalesValue: string;
34 | begin
35 | fTotalSalesValue:=fModel.GetTotalSales;
36 | result:=Format('%10.2f',[fTotalSalesValue]);
37 | end;
38 |
39 |
40 | procedure TMainViewModel.SetModel(const newModel: TMainModel);
41 | begin
42 | fModel:=newModel;
43 | end;
44 |
45 | end.
46 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/Views/View.TestPrintInvoice.fmx:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Test Print Invoice'
5 | ClientHeight = 144
6 | ClientWidth = 274
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 32.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 65.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | OnClick = ButtonPrintInvoiceClick
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/Chapter 4/POSAppMVVMMainFormTest/Views/View.TestPrintInvoice.pas:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces,
9 | Model.ProSu.Provider;
10 |
11 | type
12 | TTestPrintInvoiceForm = class(TForm)
13 | ButtonPrintInvoice: TButton;
14 | procedure FormCreate(Sender: TObject);
15 | procedure ButtonPrintInvoiceClick(Sender: TObject);
16 | private
17 | fProvider: IProviderInterface;
18 | public
19 | property Provider: IProviderInterface read fProvider;
20 | end;
21 |
22 | var
23 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
24 |
25 | implementation
26 |
27 | uses
28 | Model.Declarations, Model.ProSu.InterfaceActions;
29 | {$R *.fmx}
30 |
31 | procedure TTestPrintInvoiceForm.ButtonPrintInvoiceClick(Sender: TObject);
32 | var
33 | tmpNotificationClass: TNotificationClass;
34 | begin
35 | tmpNotificationClass:=TNotificationClass.Create;
36 | try
37 | tmpNotificationClass.Actions:=[actUpdateTotalSalesFigure];
38 | tmpNotificationClass.ActionValue:=Random(1300);
39 | fProvider.NotifySubscribers(tmpNotificationClass);
40 | finally
41 | tmpNotificationClass.Free;
42 | end;
43 | end;
44 |
45 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
46 | begin
47 | fProvider:=TProSuProvider.Create;
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fMainFormLabelsText.Title:='';
36 | fMainFormLabelsText.IssueButtonCaption:='';
37 | fMainFormLabelsText.TotalSalesText:='';
38 |
39 | fDatabase:=CreateDatabaseClass;
40 | end;
41 |
42 |
43 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
44 | begin
45 | fMainFormLabelsText.Title:='Main Screen';
46 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
47 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
48 | result:=fMainFormLabelsText;
49 | end;
50 |
51 | function TMainModel.GetTotalSales: Currency;
52 | begin
53 | result:=fDatabase.GetTotalSales;
54 | end;
55 |
56 | end.
57 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/POSAppMVVMInvoiceForm.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMInvoiceForm;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas',
16 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm},
17 | Model.Invoice in 'Models\Model.Invoice.pas',
18 | ViewModel.Invoice in 'ViewModels\ViewModel.Invoice.pas';
19 |
20 | {$R *.res}
21 |
22 | var
23 | mainModel: IMainModelInterface;
24 | mainViewModel: IMainViewModelInterface;
25 |
26 | begin
27 | mainModel:=CreateMainModelClass;
28 | mainViewModel:=CreateMainViewModelClass;
29 | mainViewModel.Model:=mainModel;
30 |
31 | Application.Initialize;
32 |
33 | MainForm:=TMainForm.Create(Application);
34 | MainForm.ViewModel:=mainViewModel;
35 |
36 | Application.MainForm:=MainForm;
37 | MainForm.Show;
38 | Application.Run;
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/POSAppMVVMInvoiceFormProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 | implementation
26 |
27 | end.
28 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMInvoiceForm/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Models/Model.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.Interfaces;
2 |
3 | interface
4 |
5 | uses
6 | Model.Declarations, System.Generics.Collections;
7 |
8 | type
9 | IDatabaseInterface = interface
10 | ['{DDE3E13A-0EC5-4712-B068-9B510977CF71}']
11 | function GetCustomerList: TObjectList;
12 | function GetCustomerFromName(const nameStr: string): TCustomer;
13 | function GetItems: TObjectList;
14 | function GetItemFromDescription(const desc: string): TItem;
15 | function GetItemFromID(const id: Integer): TItem;
16 | function GetTotalSales: Currency;
17 | procedure SaveCurrentSales(const currentSales: Currency);
18 | end;
19 |
20 | IMainModelInterface = interface
21 | ['{1345E22D-6229-4C27-8D08-6EA8584BE718}']
22 | function GetMainFormLabelsText: TMainFormLabelsText;
23 | function GetTotalSales: Currency;
24 | end;
25 |
26 | IMainViewModelInterface = interface
27 | ['{62CF0DAC-C808-4B1A-A6DC-57D7DC1912CB}']
28 | function GetModel: IMainModelInterface;
29 | procedure SetModel (const newModel: IMainModelInterface);
30 | function GetLabelsText: TMainFormLabelsText;
31 | function GetTotalSalesValue: string;
32 | property Model: IMainModelInterface read GetModel write SetModel;
33 | property LabelsText: TMainFormLabelsText read GetlabelsText;
34 | end;
35 |
36 | implementation
37 |
38 | end.
39 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fDatabase:=CreateDatabaseClass;
36 | end;
37 |
38 |
39 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
40 | begin
41 | fMainFormLabelsText.Title:='Main Screen';
42 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
43 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
44 | result:=fMainFormLabelsText;
45 | end;
46 |
47 | function TMainModel.GetTotalSales: Currency;
48 | begin
49 | result:=fDatabase.GetTotalSales;
50 | end;
51 |
52 | end.
53 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMMainFormFullInterfaces;
2 |
3 | uses
4 | EMemLeaks,
5 | EResLeaks,
6 | EDialogWinAPIMSClassic,
7 | EDialogWinAPIEurekaLogDetailed,
8 | EDialogWinAPIStepsToReproduce,
9 | EDebugExports,
10 | EDebugJCL,
11 | EFixSafeCallException,
12 | EMapWin32,
13 | EAppFMX,
14 | ExceptionLog7,
15 | System.StartUpCopy,
16 | FMX.Forms,
17 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
18 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
19 | Model.Database in 'Models\Model.Database.pas',
20 | Model.Main in 'Models\Model.Main.pas',
21 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
22 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
23 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
24 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
25 | Model.Declarations in 'Models\Model.Declarations.pas',
26 | Model.Interfaces in 'Models\Model.Interfaces.pas';
27 |
28 | {$R *.res}
29 |
30 | var
31 | mainModel: IMainModelInterface;
32 | mainViewModel: IMainViewModelInterface;
33 |
34 | begin
35 | mainModel:=CreateMainModelClass;
36 | mainViewModel:=CreateMainViewModelClass;
37 | mainViewModel.Model:=mainModel;
38 |
39 | Application.Initialize;
40 |
41 | MainForm:=TMainForm.Create(Application);
42 | MainForm.ViewModel:=mainViewModel;
43 |
44 | Application.MainForm:=MainForm;
45 | MainForm.Show;
46 | Application.Run;
47 |
48 | end.
49 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 5/POSAppMVVMMainFormFullInterfaces/POSAppMVVMMainFormFullInterfaces.res
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 |
26 | implementation
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.fmx.~1~:
--------------------------------------------------------------------------------
1 | object Form1: TForm1
2 | Left = 0
3 | Top = 0
4 | Caption = 'Form1'
5 | ClientHeight = 181
6 | ClientWidth = 374
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | end
12 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.fmx.~2~:
--------------------------------------------------------------------------------
1 | object Form1: TForm1
2 | Left = 0
3 | Top = 0
4 | Caption = 'Test Print Invoice'
5 | ClientHeight = 144
6 | ClientWidth = 274
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | DesignerMasterStyle = 0
11 | object ButtonPrintInvoice: TButton
12 | Position.X = 40.000000000000000000
13 | Position.Y = 32.000000000000000000
14 | Size.Width = 193.000000000000000000
15 | Size.Height = 65.000000000000000000
16 | Size.PlatformDefault = False
17 | TabOrder = 1
18 | Text = 'Print Invoice'
19 | end
20 | end
21 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.fmx.~3~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Test Print Invoice'
5 | ClientHeight = 144
6 | ClientWidth = 274
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 32.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 65.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | end
21 | end
22 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.fmx.~4~:
--------------------------------------------------------------------------------
1 | object TestPrintInvoiceForm: TTestPrintInvoiceForm
2 | Left = 0
3 | Top = 0
4 | Caption = 'Test Print Invoice'
5 | ClientHeight = 144
6 | ClientWidth = 274
7 | FormFactor.Width = 320
8 | FormFactor.Height = 480
9 | FormFactor.Devices = [Desktop]
10 | OnCreate = FormCreate
11 | DesignerMasterStyle = 0
12 | object ButtonPrintInvoice: TButton
13 | Position.X = 40.000000000000000000
14 | Position.Y = 32.000000000000000000
15 | Size.Width = 193.000000000000000000
16 | Size.Height = 65.000000000000000000
17 | Size.PlatformDefault = False
18 | TabOrder = 0
19 | Text = 'Print Invoice'
20 | OnClick = ButtonPrintInvoiceClick
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.pas.~1~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
8 |
9 | type
10 | TForm1 = class(TForm)
11 | private
12 | { Private declarations }
13 | public
14 | { Public declarations }
15 | end;
16 |
17 | var
18 | Form1: TForm1;
19 |
20 | implementation
21 |
22 | {$R *.fmx}
23 |
24 | end.
25 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.pas.~2~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls;
9 |
10 | type
11 | TForm1 = class(TForm)
12 | ButtonPrintInvoice: TButton;
13 | private
14 | { Private declarations }
15 | public
16 | { Public declarations }
17 | end;
18 |
19 | var
20 | Form1: TForm1;
21 |
22 | implementation
23 |
24 | {$R *.fmx}
25 |
26 | end.
27 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.pas.~3~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces,
9 | Model.ProSu.Provider;
10 |
11 | type
12 | TTestPrintInvoiceForm = class(TForm)
13 | ButtonPrintInvoice: TButton;
14 | procedure FormCreate(Sender: TObject);
15 | private
16 | fProvider: IProviderInterface;
17 | public
18 | property Provider: IProviderInterface read fProvider;
19 | end;
20 |
21 | var
22 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
23 |
24 | implementation
25 |
26 | {$R *.fmx}
27 |
28 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
29 | begin
30 | fProvider:=TProSuProvider.Create;
31 | end;
32 |
33 | end.
34 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMMainFormFullInterfaces/Views/__history/View.TestPrintInvoice.pas.~4~:
--------------------------------------------------------------------------------
1 | unit View.TestPrintInvoice;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, Model.ProSu.Interfaces,
9 | Model.ProSu.Provider;
10 |
11 | type
12 | TTestPrintInvoiceForm = class(TForm)
13 | ButtonPrintInvoice: TButton;
14 | procedure FormCreate(Sender: TObject);
15 | procedure ButtonPrintInvoiceClick(Sender: TObject);
16 | private
17 | fProvider: IProviderInterface;
18 | public
19 | property Provider: IProviderInterface read fProvider;
20 | end;
21 |
22 | var
23 | TestPrintInvoiceForm: TTestPrintInvoiceForm;
24 |
25 | implementation
26 |
27 | uses
28 | Model.Declarations, Model.ProSu.InterfaceActions;
29 | {$R *.fmx}
30 |
31 | procedure TTestPrintInvoiceForm.ButtonPrintInvoiceClick(Sender: TObject);
32 | var
33 | tmpNotificationClass: TNotificationClass;
34 | begin
35 | tmpNotificationClass:=TNotificationClass.Create;
36 | tmpNotificationClass.Actions:=[actUpdateTotalSalesFigure];
37 | tmpNotificationClass.ActionValue:=Random(1300);
38 | if Assigned(fProvider) then
39 | fProvider.NotifySubscribers(tmpNotificationClass);
40 |
41 | end;
42 |
43 | procedure TTestPrintInvoiceForm.FormCreate(Sender: TObject);
44 | begin
45 | fProvider:=TProSuProvider.Create;
46 | end;
47 |
48 | end.
49 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/Models/Model.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.Interfaces;
2 |
3 | interface
4 |
5 | uses
6 | Model.Declarations, System.Generics.Collections;
7 |
8 | type
9 | IDatabaseInterface = interface
10 | ['{DDE3E13A-0EC5-4712-B068-9B510977CF71}']
11 | function GetCustomerList: TObjectList;
12 | function GetCustomerFromName(const nameStr: string): TCustomer;
13 | function GetItems: TObjectList;
14 | function GetItemFromDescription(const desc: string): TItem;
15 | function GetItemFromID(const id: Integer): TItem;
16 | function GetTotalSales: Currency;
17 | procedure SaveCurrentSales(const currentSales: Currency);
18 | end;
19 |
20 | IMainModelInterface = interface
21 | ['{1345E22D-6229-4C27-8D08-6EA8584BE718}']
22 | function GetMainFormLabelsText: TMainFormLabelsText;
23 | function GetTotalSales: Currency;
24 | end;
25 |
26 | IMainViewModelInterface = interface
27 | ['{62CF0DAC-C808-4B1A-A6DC-57D7DC1912CB}']
28 | function GetModel: IMainModelInterface;
29 | procedure SetModel (const newModel: IMainModelInterface);
30 | function GetLabelsText: TMainFormLabelsText;
31 | function GetTotalSalesValue: string;
32 | property Model: IMainModelInterface read GetModel write SetModel;
33 | property LabelsText: TMainFormLabelsText read GetlabelsText;
34 | end;
35 |
36 | implementation
37 |
38 | end.
39 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fDatabase:=CreateDatabaseClass;
36 | end;
37 |
38 |
39 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
40 | begin
41 | fMainFormLabelsText.Title:='Main Screen';
42 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
43 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
44 | result:=fMainFormLabelsText;
45 | end;
46 |
47 | function TMainModel.GetTotalSales: Currency;
48 | begin
49 | result:=fDatabase.GetTotalSales;
50 | end;
51 |
52 | end.
53 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/POSAppMVVMStart.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMStart;
2 |
3 | uses
4 | EMemLeaks,
5 | EResLeaks,
6 | EDialogWinAPIMSClassic,
7 | EDialogWinAPIEurekaLogDetailed,
8 | EDialogWinAPIStepsToReproduce,
9 | EDebugExports,
10 | EDebugJCL,
11 | EFixSafeCallException,
12 | EMapWin32,
13 | EAppFMX,
14 | ExceptionLog7,
15 | System.StartUpCopy,
16 | FMX.Forms,
17 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
18 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
19 | Model.Database in 'Models\Model.Database.pas',
20 | Model.Main in 'Models\Model.Main.pas',
21 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
22 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
23 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
24 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
25 | Model.Declarations in 'Models\Model.Declarations.pas',
26 | Model.Interfaces in 'Models\Model.Interfaces.pas',
27 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm};
28 |
29 | {$R *.res}
30 |
31 | var
32 | mainModel: IMainModelInterface;
33 | mainViewModel: IMainViewModelInterface;
34 |
35 | begin
36 | mainModel:=CreateMainModelClass;
37 | mainViewModel:=CreateMainViewModelClass;
38 | mainViewModel.Model:=mainModel;
39 |
40 | Application.Initialize;
41 |
42 | MainForm:=TMainForm.Create(Application);
43 | MainForm.ViewModel:=mainViewModel;
44 |
45 | Application.MainForm:=MainForm;
46 | MainForm.Show;
47 | Application.Run;
48 |
49 | end.
50 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/POSAppMVVMStartProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 | IProSuSubscriberInterface = interface
26 | ['{EAB93732-9319-49A0-B2A9-9F8A3698E09F}']
27 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
28 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
29 | end;
30 |
31 | IProSuProviderInterface = interface
32 | ['{1CCA23CC-13D4-4130-BF02-AD12FB3EBADA}']
33 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
34 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
35 | procedure NotifySubscribers (const notifyClass: INotificationClass);
36 | end;
37 |
38 | implementation
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProSuProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface, IProSuProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProSuProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: IProSuSubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface, IProSuSubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: IProSuSubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 5/POSAppMVVMStart/Views/View.InvoiceForm.pas:
--------------------------------------------------------------------------------
1 | unit View.InvoiceForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.ExtCtrls, System.Rtti, FMX.Grid,
9 | FMX.Layouts, FMX.Objects, FMX.Edit, FMX.ListBox,
10 | System.Generics.Collections, FMX.ListView.Types, FMX.ListView.Appearances,
11 | FMX.ListView.Adapters.Base, FMX.ListView, FMX.Menus;
12 |
13 | type
14 | TSalesInvoiceForm = class(TForm)
15 | LabelCustomer: TLabel;
16 | PopupBoxCustomer: TPopupBox;
17 | GroupBoxCustomerDetails: TGroupBox;
18 | LabelDiscountRate: TLabel;
19 | LabelDiscountRateFigure: TLabel;
20 | LabelTotalBalanceBig: TLabel;
21 | LabelOutstandingBalance: TLabel;
22 | LabelInvoiceBalance: TLabel;
23 | GroupBoxInvoiceItems: TGroupBox;
24 | PopupBoxItems: TPopupBox;
25 | LabelItem: TLabel;
26 | GroupBoxBalance: TGroupBox;
27 | LabelRunningBalance: TLabel;
28 | LabelInvBalance: TLabel;
29 | CheckBoxDiscount: TCheckBox;
30 | LabelDiscount: TLabel;
31 | LineHorizontal: TLine;
32 | LabelTotalBalance: TLabel;
33 | ButtonCancel: TButton;
34 | ButtonPrintInvoice: TButton;
35 | LabelQuantity: TLabel;
36 | EditQuantity: TEdit;
37 | ButtonAddItem: TButton;
38 | StringGridItems: TStringGrid;
39 | StringColumn1: TStringColumn;
40 | StringColumn2: TStringColumn;
41 | StringColumn3: TStringColumn;
42 | StringColumn4: TStringColumn;
43 | LabelTotal: TLabel;
44 | AniIndicatorProgress: TAniIndicator;
45 | LabelPrinting: TLabel;
46 | LabelTitle: TLabel;
47 | PopupMenuItems: TPopupMenu;
48 | MenuItemDeleteItem: TMenuItem;
49 | StringColumn5: TStringColumn;
50 | public
51 | { Public declarations }
52 | end;
53 |
54 | implementation
55 |
56 | {$R *.fmx}
57 |
58 | end.
59 |
--------------------------------------------------------------------------------
/Chapter 5/Thin Forms/View.InvoiceForm.pas:
--------------------------------------------------------------------------------
1 | unit InvoiceForm;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7 | FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
8 | FMX.Controls.Presentation, FMX.StdCtrls, FMX.ExtCtrls, System.Rtti, FMX.Grid,
9 | FMX.Layouts, FMX.Objects, FMX.Edit, FMX.ListBox,
10 | System.Generics.Collections, FMX.ListView.Types, FMX.ListView.Appearances,
11 | FMX.ListView.Adapters.Base, FMX.ListView, FMX.Menus;
12 |
13 | type
14 | TSalesInvoiceForm = class(TForm)
15 | LabelCustomer: TLabel;
16 | PopupBoxCustomer: TPopupBox;
17 | GroupBoxCustomerDetails: TGroupBox;
18 | LabelDiscountRate: TLabel;
19 | LabelDiscountRateFigure: TLabel;
20 | LabelTotalBalanceBig: TLabel;
21 | LabelOutstandingBalance: TLabel;
22 | LabelInvoiceBalance: TLabel;
23 | GroupBoxInvoiceItems: TGroupBox;
24 | PopupBoxItems: TPopupBox;
25 | LabelItem: TLabel;
26 | GroupBoxBalance: TGroupBox;
27 | LabelRunningBalance: TLabel;
28 | LabelInvBalance: TLabel;
29 | CheckBoxDiscount: TCheckBox;
30 | LabelDiscount: TLabel;
31 | LineHorizontal: TLine;
32 | LabelTotalBalance: TLabel;
33 | ButtonCancel: TButton;
34 | ButtonPrintInvoice: TButton;
35 | LabelQuantity: TLabel;
36 | EditQuantity: TEdit;
37 | ButtonAddItem: TButton;
38 | StringGridItems: TStringGrid;
39 | StringColumn1: TStringColumn;
40 | StringColumn2: TStringColumn;
41 | StringColumn3: TStringColumn;
42 | StringColumn4: TStringColumn;
43 | LabelTotal: TLabel;
44 | AniIndicatorProgress: TAniIndicator;
45 | LabelPrinting: TLabel;
46 | LabelTitle: TLabel;
47 | PopupMenuItems: TPopupMenu;
48 | MenuItemDeleteItem: TMenuItem;
49 | StringColumn5: TStringColumn;
50 | public
51 | { Public declarations }
52 | end;
53 |
54 | implementation
55 |
56 | {$R *.fmx}
57 |
58 | end.
59 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fMainFormLabelsText.Title:='';
36 | fMainFormLabelsText.IssueButtonCaption:='';
37 | fMainFormLabelsText.TotalSalesText:='';
38 |
39 | fDatabase:=CreateDatabaseClass;
40 | end;
41 |
42 |
43 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
44 | begin
45 | fMainFormLabelsText.Title:='Main Screen';
46 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
47 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
48 | result:=fMainFormLabelsText;
49 | end;
50 |
51 | function TMainModel.GetTotalSales: Currency;
52 | begin
53 | result:=fDatabase.GetTotalSales;
54 | end;
55 |
56 | end.
57 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/POSAppMVVMInvoiceForm.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMInvoiceForm;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas',
16 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm},
17 | Model.Invoice in 'Models\Model.Invoice.pas',
18 | ViewModel.Invoice in 'ViewModels\ViewModel.Invoice.pas';
19 |
20 | {$R *.res}
21 |
22 | var
23 | mainModel: IMainModelInterface;
24 | mainViewModel: IMainViewModelInterface;
25 |
26 | begin
27 | mainModel:=CreateMainModelClass;
28 | mainViewModel:=CreateMainViewModelClass;
29 | mainViewModel.Model:=mainModel;
30 |
31 | Application.Initialize;
32 |
33 | MainForm:=TMainForm.Create(Application);
34 | MainForm.ViewModel:=mainViewModel;
35 |
36 | Application.MainForm:=MainForm;
37 | MainForm.Show;
38 | Application.Run;
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/POSAppMVVMInvoiceForm.stat:
--------------------------------------------------------------------------------
1 | [Stats]
2 | EditorSecs=130
3 | DesignerSecs=1
4 | InspectorSecs=1
5 | CompileSecs=68210
6 | OtherSecs=74
7 | StartTime=10/08/2016 09:52:30
8 | RealKeys=0
9 | EffectiveKeys=0
10 | DebugSecs=90
11 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/POSAppMVVMInvoiceFormProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 | implementation
26 |
27 | end.
28 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMInvoiceForm/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fMainFormLabelsText.Title:='';
36 | fMainFormLabelsText.IssueButtonCaption:='';
37 | fMainFormLabelsText.TotalSalesText:='';
38 |
39 | fDatabase:=CreateDatabaseClass;
40 | end;
41 |
42 |
43 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
44 | begin
45 | fMainFormLabelsText.Title:='Main Screen';
46 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
47 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
48 | result:=fMainFormLabelsText;
49 | end;
50 |
51 | function TMainModel.GetTotalSales: Currency;
52 | begin
53 | result:=fDatabase.GetTotalSales;
54 | end;
55 |
56 | end.
57 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/POSAppMVVMUserInteraction.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMUserInteraction;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas',
16 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm},
17 | Model.Invoice in 'Models\Model.Invoice.pas',
18 | ViewModel.Invoice in 'ViewModels\ViewModel.Invoice.pas';
19 |
20 | {$R *.res}
21 |
22 | var
23 | mainModel: IMainModelInterface;
24 | mainViewModel: IMainViewModelInterface;
25 |
26 | begin
27 | mainModel:=CreateMainModelClass;
28 | mainViewModel:=CreateMainViewModelClass;
29 | mainViewModel.Model:=mainModel;
30 |
31 | Application.Initialize;
32 |
33 | MainForm:=TMainForm.Create(Application);
34 | MainForm.ViewModel:=mainViewModel;
35 |
36 | Application.MainForm:=MainForm;
37 | MainForm.Show;
38 | Application.Run;
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/POSAppMVVMUserInteractionProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure, actInvoiceItemsChanged);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 |
26 | implementation
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 6/POSAppMVVMUserInteraction/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fDatabase:=CreateDatabaseClass;
36 | end;
37 |
38 |
39 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
40 | begin
41 | fMainFormLabelsText.Title:='Main Screen';
42 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
43 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
44 | result:=fMainFormLabelsText;
45 | end;
46 |
47 | function TMainModel.GetTotalSales: Currency;
48 | begin
49 | result:=fDatabase.GetTotalSales;
50 | end;
51 |
52 | end.
53 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/POSAppMVVMFinal.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMFinal;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas',
16 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm},
17 | Model.Invoice in 'Models\Model.Invoice.pas',
18 | ViewModel.Invoice in 'ViewModels\ViewModel.Invoice.pas';
19 |
20 | {$R *.res}
21 |
22 | var
23 | mainModel: IMainModelInterface;
24 | mainViewModel: IMainViewModelInterface;
25 |
26 | begin
27 | mainModel:=CreateMainModelClass;
28 | mainViewModel:=CreateMainViewModelClass;
29 | mainViewModel.Model:=mainModel;
30 |
31 | Application.Initialize;
32 |
33 | MainForm:=TMainForm.Create(Application);
34 | MainForm.ViewModel:=mainViewModel;
35 |
36 | Application.MainForm:=MainForm;
37 | MainForm.Show;
38 | Application.Run;
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/POSAppMVVMFinalProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure, actInvoiceItemsChanges,
7 | actPrintingStart, actPrintingFinish);
8 | TInterfaceError = (errInvoiceItemEmpty, errInvoiceItemQuantityEmpty,
9 | errInvoiceItemQuantityNonPositive,
10 | errInvoiceItemQuantityNotNumber, errNoError);
11 | TInterfaceActions = set of TInterfaceAction;
12 | TInterfaceErrors = set of TInterfaceError;
13 |
14 | implementation
15 |
16 | end.
17 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 |
26 | implementation
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Database.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Database.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Declarations.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Declarations.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Interfaces.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Interfaces.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Invoice.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Invoice.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Main.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.Main.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.InterfaceActions.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.InterfaceActions.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Interfaces.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Interfaces.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Provider.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Provider.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Subscriber.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/Model.ProSu.Subscriber.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/POSAppMVVMFinal.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/POSAppMVVMFinal.exe
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/View.InvoiceForm.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/View.InvoiceForm.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/View.MainForm.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/View.MainForm.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/ViewModel.Invoice.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/ViewModel.Invoice.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMFinal/Win32/Debug/ViewModel.Main.dcu:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/Chapter 7/POSAppMVVMFinal/Win32/Debug/ViewModel.Main.dcu
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/Models/Model.Main.pas:
--------------------------------------------------------------------------------
1 | unit Model.Main;
2 |
3 | interface
4 |
5 | uses Model.Declarations, Model.Database, Model.Interfaces;
6 |
7 | function CreateMainModelClass: IMainModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainModel = class(TInterfacedObject, IMainModelInterface)
16 | private
17 | fMainFormLabelsText: TMainFormLabelsText;
18 | fDatabase: IDatabaseInterface;
19 | public
20 | function GetMainFormLabelsText: TMainFormLabelsText;
21 | function GetTotalSales: Currency;
22 | constructor Create;
23 | end;
24 |
25 |
26 | function CreateMainModelClass: IMainModelInterface;
27 | begin
28 | result:=TMainModel.Create;
29 | end;
30 |
31 | { TMainModel }
32 |
33 | constructor TMainModel.Create;
34 | begin
35 | fMainFormLabelsText.Title:='';
36 | fMainFormLabelsText.IssueButtonCaption:='';
37 | fMainFormLabelsText.TotalSalesText:='';
38 |
39 | fDatabase:=CreateDatabaseClass;
40 | end;
41 |
42 |
43 | function TMainModel.GetMainFormLabelsText: TMainFormLabelsText;
44 | begin
45 | fMainFormLabelsText.Title:='Main Screen';
46 | fMainFormLabelsText.IssueButtonCaption:='Issue Invoice';
47 | fMainFormLabelsText.TotalSalesText:='Total Sales:';
48 | result:=fMainFormLabelsText;
49 | end;
50 |
51 | function TMainModel.GetTotalSales: Currency;
52 | begin
53 | result:=fDatabase.GetTotalSales;
54 | end;
55 |
56 | end.
57 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/POSAppMVVMUserInteraction.dpr:
--------------------------------------------------------------------------------
1 | program POSAppMVVMUserInteraction;
2 |
3 | uses
4 | System.StartUpCopy,
5 | FMX.Forms,
6 | View.MainForm in 'Views\View.MainForm.pas' {MainForm},
7 | ViewModel.Main in 'ViewModels\ViewModel.Main.pas',
8 | Model.Database in 'Models\Model.Database.pas',
9 | Model.Main in 'Models\Model.Main.pas',
10 | Model.ProSu.Interfaces in 'SupportCode\Model.ProSu.Interfaces.pas',
11 | Model.ProSu.Provider in 'SupportCode\Model.ProSu.Provider.pas',
12 | Model.ProSu.Subscriber in 'SupportCode\Model.ProSu.Subscriber.pas',
13 | Model.ProSu.InterfaceActions in 'SupportCode\Model.ProSu.InterfaceActions.pas',
14 | Model.Declarations in 'Models\Model.Declarations.pas',
15 | Model.Interfaces in 'Models\Model.Interfaces.pas',
16 | View.InvoiceForm in 'Views\View.InvoiceForm.pas' {SalesInvoiceForm},
17 | Model.Invoice in 'Models\Model.Invoice.pas',
18 | ViewModel.Invoice in 'ViewModels\ViewModel.Invoice.pas';
19 |
20 | {$R *.res}
21 |
22 | var
23 | mainModel: IMainModelInterface;
24 | mainViewModel: IMainViewModelInterface;
25 |
26 | begin
27 | mainModel:=CreateMainModelClass;
28 | mainViewModel:=CreateMainViewModelClass;
29 | mainViewModel.Model:=mainModel;
30 |
31 | Application.Initialize;
32 |
33 | MainForm:=TMainForm.Create(Application);
34 | MainForm.ViewModel:=mainViewModel;
35 |
36 | Application.MainForm:=MainForm;
37 | MainForm.Show;
38 | Application.Run;
39 |
40 | end.
41 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/POSAppMVVMUserInteractionProjectGroup.groupproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {F0830607-CEE2-4F6D-9251-4E422F2EAA71}
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Default.Personality.12
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.InterfaceActions.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.InterfaceActions;
2 |
3 | interface
4 |
5 | type
6 | TInterfaceAction = (actUpdateTotalSalesFigure, actInvoiceItemsChanged);
7 | TInterfaceActions = set of TInterfaceAction;
8 |
9 | implementation
10 |
11 | end.
12 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Interfaces.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Interfaces;
2 |
3 | interface
4 |
5 | type
6 | INotificationClass = interface
7 | ['{2BB04DBB-6D61-4E4F-8C70-8BCC8E36FDE4}']
8 | end;
9 |
10 | TUpdateSubscriberMethod = procedure (const notifyClass: INotificationClass) of object;
11 |
12 | ISubscriberInterface = interface
13 | ['{955BF992-F4FA-4141-9C0F-04600C582C00}']
14 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
15 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
16 | end;
17 |
18 | IProviderInterface = interface
19 | ['{DD326AE1-5049-43AA-9215-DF53DB5FC958}']
20 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
21 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
22 | procedure NotifySubscribers (const notifyClass: INotificationClass);
23 | end;
24 |
25 |
26 | implementation
27 |
28 | end.
29 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Provider.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Provider;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces, System.Generics.Collections;
6 |
7 | function CreateProSuProviderClass: IProviderInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuProvider = class (TInterfacedObject, IProviderInterface)
13 | private
14 | fSubscriberList: TList;
15 | public
16 | procedure Subscribe(const tmpSubscriber: ISubscriberInterface);
17 | procedure Unsubscribe(const tmpSubscriber: ISubscriberInterface);
18 | procedure NotifySubscribers (const notifyClass: INotificationClass);
19 |
20 | constructor Create;
21 | destructor Destroy; override;
22 | end;
23 |
24 | { TProSuProvider }
25 |
26 | constructor TProSuProvider.Create;
27 | begin
28 | inherited;
29 | fSubscriberList:=TList.Create;
30 | end;
31 |
32 | destructor TProSuProvider.Destroy;
33 | var
34 | iTemp: ISubscriberInterface;
35 | begin
36 | for itemp in fSubscriberList do
37 | Unsubscribe(iTemp);
38 | fSubscriberList.Free;
39 | inherited;
40 | end;
41 |
42 | procedure TProSuProvider.NotifySubscribers(const notifyClass: INotificationClass);
43 | var
44 | tmpSubscriber: ISubscriberInterface;
45 | begin
46 | for tmpSubscriber in fSubscriberList do
47 | tmpSubscriber.UpdateSubscriber(notifyClass);
48 | end;
49 |
50 | procedure TProSuProvider.Subscribe(const tmpSubscriber: ISubscriberInterface);
51 | begin
52 | fSubscriberList.Add(tmpSubscriber);
53 | end;
54 |
55 | procedure TProSuProvider.Unsubscribe(const tmpSubscriber: ISubscriberInterface);
56 | begin
57 | fSubscriberList.Remove(tmpSubscriber);
58 | end;
59 |
60 | function CreateProSuProviderClass: IProviderInterface;
61 | begin
62 | result:=TProSuProvider.Create;
63 | end;
64 |
65 | end.
66 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/SupportCode/Model.ProSu.Subscriber.pas:
--------------------------------------------------------------------------------
1 | unit Model.ProSu.Subscriber;
2 |
3 | interface
4 |
5 | uses Model.ProSu.Interfaces;
6 |
7 | function CreateProSuSubscriberClass: ISubscriberInterface;
8 |
9 | implementation
10 |
11 | type
12 | TProSuSubscriber = class (TInterfacedObject, ISubscriberInterface)
13 | private
14 | fUpdateMethod: TUpdateSubscriberMethod;
15 | public
16 | procedure UpdateSubscriber (const notifyClass: INotificationClass);
17 | procedure SetUpdateSubscriberMethod (newMethod: TUpdateSubscriberMethod);
18 | end;
19 |
20 | { TProSuSubscriber }
21 |
22 | procedure TProSuSubscriber.SetUpdateSubscriberMethod(
23 | newMethod: TUpdateSubscriberMethod);
24 | begin
25 | fUpdateMethod:=newMethod;
26 | end;
27 |
28 | procedure TProSuSubscriber.UpdateSubscriber(const notifyClass: INotificationClass);
29 | begin
30 | if Assigned(fUpdateMethod) then
31 | fUpdateMethod(notifyClass);
32 | end;
33 |
34 | function CreateProSuSubscriberClass: ISubscriberInterface;
35 | begin
36 | result:=TProSuSubscriber.Create;
37 | end;
38 |
39 | end.
40 |
--------------------------------------------------------------------------------
/Chapter 7/POSAppMVVMUserInteraction/ViewModels/ViewModel.Main.pas:
--------------------------------------------------------------------------------
1 | unit ViewModel.Main;
2 |
3 | interface
4 |
5 | uses Model.Main, Model.Declarations, Model.Interfaces;
6 |
7 | function CreateMainViewModelClass: IMainViewModelInterface;
8 |
9 | implementation
10 |
11 | uses
12 | System.SysUtils;
13 |
14 | type
15 | TMainViewModel = class(TInterfacedObject, IMainViewModelInterface)
16 | private
17 | fModel: IMainModelInterface;
18 | fLabelsText: TMainFormLabelsText;
19 | fTotalSalesValue: Currency;
20 | function GetModel: IMainModelInterface;
21 | procedure SetModel (const newModel: IMainModelInterface);
22 | function GetLabelsText: TMainFormLabelsText;
23 | public
24 | property Model: IMainModelInterface read fModel write SetModel;
25 | property LabelsText: TMainFormLabelsText read GetlabelsText;
26 | function GetTotalSalesValue: string;
27 | end;
28 |
29 |
30 | function CreateMainViewModelClass: IMainViewModelInterface;
31 | begin
32 | result:=TMainViewModel.Create;
33 | end;
34 |
35 | { TMainViewModel }
36 |
37 | function TMainViewModel.GetLabelsText: TMainFormLabelsText;
38 | begin
39 | fLabelsText:=fModel.GetMainFormLabelsText;
40 | result:=fLabelsText;
41 | end;
42 |
43 | function TMainViewModel.GetModel: IMainModelInterface;
44 | begin
45 | result:=fModel;
46 | end;
47 |
48 | function TMainViewModel.GetTotalSalesValue: string;
49 | begin
50 | fTotalSalesValue:=fModel.GetTotalSales;
51 | result:=Format('%10.2f',[fTotalSalesValue]);
52 | end;
53 |
54 |
55 | procedure TMainViewModel.SetModel(const newModel: IMainModelInterface);
56 | begin
57 | fModel:=newModel;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/mvvm-in-delphi/f189b4d33bcd2ae25b521de50588583809f316d1/LICENSE.txt
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository accompanies [*MVVM in Delphi*](http://www.apress.com/9781484222133) by John Kouraklis (Apress, 2016).
4 |
5 | 
6 |
7 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
8 |
9 | ## Releases
10 |
11 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
12 |
13 | ## Contributions
14 |
15 | See the file Contributing.md for more information on how you can contribute to this repository.
16 |
--------------------------------------------------------------------------------
/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Apress Source Code
2 |
3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
4 |
5 | ## How to Contribute
6 |
7 | 1. Make sure you have a GitHub account.
8 | 2. Fork the repository for the relevant book.
9 | 3. Create a new branch on which to make your change, e.g.
10 | `git checkout -b my_code_contribution`
11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
12 | 5. Submit a pull request.
13 |
14 | Thank you for your contribution!
--------------------------------------------------------------------------------