unit View.MainView;
interface
uses
de.itnets.Events,
de.itnets.References,
MVVM.ViewModel.ViewModelBase,
ViewModel.MainViewModel,
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
MVVM.View.FMX.Form.Base, FMX.Controls.Presentation, FMX.Edit;
type
TMainView =
class( TViewBaseForm )
BarEdit: TEdit;
{ OnChangeTracking -> ControlChanged }
FooEdit: TEdit;
{ OnChangeTracking -> ControlChanged }
CheckLabel: TLabel;
private
FMain: WeakRef<TMainViewModel>;
protected
procedure AttachToViewModel( AViewModel: TViewModelBase );
override;
procedure DetachFromViewModel( AViewModel: TViewModelBase );
override;
procedure ViewModelPropertyChanged( Sender: TObject;
const e: TPropertyChangedArgs );
override;
public
published
procedure ControlChanged( Sender: TObject );
end;
var
MainView: TMainView;
implementation
{$R *.fmx}
{ TMainView }
procedure TMainView.AttachToViewModel( AViewModel: TViewModelBase );
begin
FMain := AViewModel
as TMainViewModel;
inherited;
end;
procedure TMainView.ControlChanged( Sender: TObject );
begin
if FMain.IsAssigned
then
begin
FMain.Reference.Bar := BarEdit.Text;
FMain.Reference.Foo := FooEdit.Text;
end;
end;
procedure TMainView.DetachFromViewModel( AViewModel: TViewModelBase );
begin
inherited;
FMain :=
nil;
end;
procedure TMainView.ViewModelPropertyChanged( Sender: TObject;
const e: TPropertyChangedArgs );
begin
inherited;
if FMain.IsAssigned
then
begin
if e.Match( '
Bar' )
then
BarEdit.Text := FMain.Reference.Bar;
if e.Match( '
Foo' )
then
FooEdit.Text := FMain.Reference.Foo;
if e.Matches( ['
Bar', '
Foo'] )
then
CheckLabel.Text := Format( '
Bar: "%s", Foo: "%s"', [FMain.Reference.Bar, FMain.Reference.Foo] );
end;
end;
end.