diff --git a/Knockoff.Binding.Components.pas b/Knockoff.Binding.Components.pas index 381a0de..e090c51 100644 --- a/Knockoff.Binding.Components.pas +++ b/Knockoff.Binding.Components.pas @@ -14,6 +14,7 @@ interface Classes, Rtti, StdCtrls, + ComCtrls, SysUtils, Knockoff.Observable; @@ -87,6 +88,13 @@ TCheckBoxBinding = class(TBinding) procedure InitTarget; override; end; + TTrackBarBinding = class(TBinding) + protected + procedure HandleChange(Sender: TObject); + function InitGetValue(const observable: IObservable): TFunc; override; + procedure InitTarget; override; + end; + function GetBindingClass(const target: TObject; const expression: string): TBindingClass; implementation @@ -107,6 +115,8 @@ function GetBindingClass(const target: TObject; const expression: string): TBind Result := TButtonBinding else if (target is TCheckBox) and SameText(expression, 'Checked') then Result := TCheckBoxBinding + else if (target is TTrackBar) and SameText(expression, 'Position') then + Result := TTrackBarBinding else Result := nil; end; @@ -357,4 +367,28 @@ function TCheckBoxBinding.InitGetValue( {$ENDREGION} +{$REGION 'TTrackBarBinding'} + +procedure TTrackBarBinding.HandleChange(Sender: TObject); +begin + Source.Value := Target.Position; +end; + +procedure TTrackBarBinding.InitTarget; +begin + Target.OnChange := HandleChange; +end; + +function TTrackBarBinding.InitGetValue(const observable: IObservable): TFunc; +begin + Result := + function: TValue + begin + Target.Position := observable.Value.ToType; + end; +end; + +{$ENDREGION} + + end.