Skip to content

Commit

Permalink
added checkbox binding
Browse files Browse the repository at this point in the history
  • Loading branch information
sglienke committed Jun 15, 2015
1 parent a4606a7 commit e60900f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions SimpleMVVM.Binding.Components.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ TLabelBinding = class(TBinding<TLabel>)
function InitGetValue(const observable: IObservable): TFunc<TValue>; override;
end;

TCheckBoxBinding = class(TBinding<TCheckBox>)
protected
procedure HandleClick(Sender: TObject);
function InitGetValue(const observable: IObservable): TFunc<TValue>; override;
procedure InitTarget; override;
end;

function GetBindingClass(const target: TObject; const expression: string): TBindingClass;

implementation
Expand All @@ -98,6 +105,8 @@ function GetBindingClass(const target: TObject; const expression: string): TBind
Result := TLabelBinding
else if (target is TButton) and SameText(expression, 'Click') then
Result := TButtonBinding
else if (target is TCheckBox) and SameText(expression, 'Checked') then
Result := TCheckBoxBinding
else
Result := nil;
end;
Expand Down Expand Up @@ -323,4 +332,29 @@ function TLabelBinding.InitGetValue(const observable: IObservable): TFunc<TValue
{$ENDREGION}


{$REGION 'TCheckBoxBinding'}

procedure TCheckBoxBinding.HandleClick(Sender: TObject);
begin
Source.Value := Target.Checked;
end;

procedure TCheckBoxBinding.InitTarget;
begin
Target.OnClick := HandleClick;
end;

function TCheckBoxBinding.InitGetValue(
const observable: IObservable): TFunc<TValue>;
begin
Result :=
function: TValue
begin
Target.Checked := observable.Value.AsBoolean;
end;
end;

{$ENDREGION}


end.

0 comments on commit e60900f

Please sign in to comment.