diff --git a/Main.dfm b/MainView.dfm similarity index 98% rename from Main.dfm rename to MainView.dfm index 25bc756..e3eab42 100644 --- a/Main.dfm +++ b/MainView.dfm @@ -1,4 +1,4 @@ -object MainForm: TMainForm +object MainViewForm: TMainViewForm Left = 0 Top = 0 Caption = 'SimpleMVVMDemo' diff --git a/MainView.pas b/MainView.pas new file mode 100644 index 0000000..92b9348 --- /dev/null +++ b/MainView.pas @@ -0,0 +1,64 @@ +unit MainView; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, StdCtrls, SimpleMVVM.Binding; + +type + TMainViewForm = class(TForm) + + GroupBox1: TGroupBox; + [Bind('Value', 'FirstName')] + edtFirstName: TEdit; + [Bind('Value', 'LastName')] + edtLastName: TEdit; + [Bind('Text', 'FullName')] + lblFullName: TLabel; + + GroupBox2: TGroupBox; + [Bind('Click', 'RegisterClick')] + [Bind('Disabled', 'HasClickedTooManyTimes')] + btnRegisterClick: TButton; + [Bind('Text', 'NumberOfClicks')] + lblClickCount: TLabel; + [Bind('Click', 'ResetClicks')] + [Bind('Visible', 'HasClickedTooManyTimes')] + btnResetClicks: TButton; + [Bind('Visible', 'HasClickedTooManyTimes')] + lblClickedTooManyTimes: TLabel; + + GroupBox3: TGroupBox; + [Bind('Value', 'ChosenTicket')] + [BindOptions('Tickets')] + [BindOptionsCaption('Choose...')] + [BindOptionsText('Name')] + cbTickets: TComboBox; + [Bind('Text', 'ChosenTicket.Price')] + lblPrice: TLabel; + [Bind('Click', 'ResetTicket')] + [Bind('Enabled', 'ChosenTicket')] + btnClear: TButton; + + procedure FormCreate(Sender: TObject); + end; + +var + MainViewForm: TMainViewForm; + +implementation + +{$R *.dfm} + +uses + MainViewModel; + +{ TMainForm } + +procedure TMainViewForm.FormCreate(Sender: TObject); +begin + ApplyBindings(Self, TViewModel.Create('John', 'Doe')); +end; + +end. diff --git a/Main.pas b/MainViewModel.pas similarity index 68% rename from Main.pas rename to MainViewModel.pas index 40cc130..0172212 100644 --- a/Main.pas +++ b/MainViewModel.pas @@ -1,57 +1,9 @@ -unit Main; +unit MainViewModel; interface uses - Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, - Dialogs, StdCtrls, SimpleMVVM.Binding; - -type - TMainForm = class(TForm) - - GroupBox1: TGroupBox; - [Bind('Value', 'FirstName')] - edtFirstName: TEdit; - [Bind('Value', 'LastName')] - edtLastName: TEdit; - [Bind('Text', 'FullName')] - lblFullName: TLabel; - - GroupBox2: TGroupBox; - [Bind('Click', 'RegisterClick')] - [Bind('Disabled', 'HasClickedTooManyTimes')] - btnRegisterClick: TButton; - [Bind('Text', 'NumberOfClicks')] - lblClickCount: TLabel; - [Bind('Click', 'ResetClicks')] - [Bind('Visible', 'HasClickedTooManyTimes')] - btnResetClicks: TButton; - [Bind('Visible', 'HasClickedTooManyTimes')] - lblClickedTooManyTimes: TLabel; - - GroupBox3: TGroupBox; - [Bind('Value', 'ChosenTicket')] - [BindOptions('Tickets')] - [BindOptionsCaption('Choose...')] - [BindOptionsText('Name')] - cbTickets: TComboBox; - [Bind('Text', 'ChosenTicket.Price')] - lblPrice: TLabel; - [Bind('Click', 'ResetTicket')] - [Bind('Enabled', 'ChosenTicket')] - btnClear: TButton; - - procedure FormCreate(Sender: TObject); - end; - -var - MainForm: TMainForm; - -implementation - -{$R *.dfm} - -uses + Classes, Generics.Collections, SimpleMVVM.Observable; @@ -98,6 +50,8 @@ TViewModel = class(TComponent) property Tickets: TList read fTickets; end; +implementation + { TTicket } constructor TTicket.Create(const name: string; price: Currency); @@ -169,11 +123,4 @@ procedure TViewModel.SetLastName(const value: string); fLastName.Value := value; end; -{ TMainForm } - -procedure TMainForm.FormCreate(Sender: TObject); -begin - ApplyBindings(Self, TViewModel.Create('John', 'Doe')); -end; - end. diff --git a/SimpleMVVM.Binding.pas b/SimpleMVVM.Binding.pas index ecd8664..f6201c0 100644 --- a/SimpleMVVM.Binding.pas +++ b/SimpleMVVM.Binding.pas @@ -67,7 +67,7 @@ procedure ApplyBindings(const view: TComponent; const viewModel: TObject); f: TRttiField; a: TCustomAttribute; begin - if (viewModel is TComponent) then + if viewModel is TComponent then if TComponent(viewModel).Owner = nil then view.InsertComponent(TComponent(viewModel)); diff --git a/SimpleMVVMDemo.dpr b/SimpleMVVMDemo.dpr index 706e918..d790465 100644 --- a/SimpleMVVMDemo.dpr +++ b/SimpleMVVMDemo.dpr @@ -2,16 +2,15 @@ program SimpleMVVMDemo; uses Forms, - Main in 'Main.pas' {MainForm}, - SimpleMVVM.Binding in 'SimpleMVVM.Binding.pas', - SimpleMVVM.Binding.Components in 'SimpleMVVM.Binding.Components.pas'; + MainView in 'MainView.pas' {MainViewForm}, + MainViewModel in 'MainViewModel.pas'; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; - Application.CreateForm(TMainForm, MainForm); + Application.CreateForm(TMainViewForm, MainViewForm); Application.Run; ReportMemoryLeaksOnShutdown := True; end. diff --git a/SimpleMVVMDemo.dproj b/SimpleMVVMDemo.dproj index 9613859..c48d69a 100644 --- a/SimpleMVVMDemo.dproj +++ b/SimpleMVVMDemo.dproj @@ -1,7 +1,7 @@  {49FC422F-A839-4326-8632-DDD0661BF466} - 16.1 + 17.1 VCL SimpleMVVMDemo.dpr True @@ -13,6 +13,16 @@ true + + true + Base + true + + + true + Base + true + true Base @@ -51,6 +61,20 @@ false false + + Debug + $(MSBuildProjectName) + CFBundleName=$(MSBuildProjectName);CFBundleDevelopmentRegion=en;CFBundleDisplayName=$(MSBuildProjectName);CFBundleIdentifier=$(MSBuildProjectName);CFBundleInfoDictionaryVersion=7.1;CFBundleVersion=1.0.0.0;CFBundlePackageType=APPL;CFBundleSignature=????;LSRequiresIPhoneOS=true;CFBundleAllowMixedLocalizations=YES;CFBundleExecutable=$(MSBuildProjectName);UIDeviceFamily=iPhone & iPad;CFBundleResourceSpecification=ResourceRules.plist;NSLocationAlwaysUsageDescription=The reason for accessing the location information of the user;NSLocationWhenInUseUsageDescription=The reason for accessing the location information of the user;FMLocalNotificationPermission=false + true + iPhoneAndiPad + + + Debug + $(MSBuildProjectName) + CFBundleName=$(MSBuildProjectName);CFBundleDevelopmentRegion=en;CFBundleDisplayName=$(MSBuildProjectName);CFBundleIdentifier=$(MSBuildProjectName);CFBundleInfoDictionaryVersion=7.1;CFBundleVersion=1.0.0.0;CFBundlePackageType=APPL;CFBundleSignature=????;LSRequiresIPhoneOS=true;CFBundleAllowMixedLocalizations=YES;CFBundleExecutable=$(MSBuildProjectName);UIDeviceFamily=iPhone & iPad;CFBundleResourceSpecification=ResourceRules.plist;NSLocationAlwaysUsageDescription=The reason for accessing the location information of the user;NSLocationWhenInUseUsageDescription=The reason for accessing the location information of the user;FMLocalNotificationPermission=false + true + iPhoneAndiPad + true Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) @@ -83,12 +107,11 @@ MainSource - -
MainForm
+ +
MainViewForm
dfm
- - + Cfg_2 Base @@ -110,7 +133,7 @@ SimpleMVVMDemo.dpr - + SimpleMVVMDemo.exe @@ -118,7 +141,7 @@ - + 1 .dylib @@ -135,9 +158,13 @@ 1 .dylib + + 1 + .dylib + - + 1 .dylib @@ -154,14 +181,21 @@ 1 .dylib + + 1 + .dylib + - + 1 1 + + 1 + @@ -170,7 +204,11 @@ - + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 1 @@ -188,12 +226,15 @@ - + 1 1 + + 1 + @@ -208,12 +249,15 @@ - + 1 1 + + 1 + @@ -228,12 +272,15 @@ - + 1 1 + + 1 + @@ -282,7 +329,11 @@ - + + ../ + 1 + + ../ 1 @@ -307,20 +358,26 @@ - + 1 1 + + 1 + - + 1 1 + + 1 + @@ -335,26 +392,32 @@ - + + 1 + + 1 - + 1 1 - - - + 1 + + library\lib\armeabi-v7a 1 + + 1 + 0 @@ -365,6 +428,9 @@ 1 + + 1 + @@ -379,10 +445,10 @@ - + 0 - + 0 @@ -395,14 +461,20 @@ 0 + + 0 + - + 1 1 + + 1 + @@ -417,12 +489,15 @@ - + 1 1 + + 1 + @@ -441,14 +516,17 @@ 1 + - + - + + False + False True False