Skip to content

Commit

Permalink
added convention based ApplyBindings routine
Browse files Browse the repository at this point in the history
  • Loading branch information
sglienke committed Jun 15, 2015
1 parent 3972135 commit e4fa8b2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions SimpleMVVM.Binding.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ BindOptionsTextAttribute = class(TCustomAttribute)
end;

procedure ApplyBindings(const view: TComponent; const viewModel: TObject);
procedure ApplyBindingsByConventions(const view: TComponent; const viewModel: TObject);

procedure Bind(const target: TComponent; const targetExpression: string;
const source: TObject; const sourceExpression: string);
Expand Down Expand Up @@ -82,6 +83,31 @@ procedure ApplyBindings(const view: TComponent; const viewModel: TObject);
viewModel);
end;

procedure ApplyBindingsByConventions(const view: TComponent; const viewModel: TObject);
var
target: TComponent;
typ: TRttiType;
prop: TRttiProperty;
begin
if viewModel is TComponent then
if TComponent(viewModel).Owner = nil then
view.InsertComponent(TComponent(viewModel));

typ := ctx.GetType(viewModel.ClassInfo);
for target in view do
begin
prop := typ.GetProperty(target.Name);
if prop <> nil then
begin
// hardcoded for now
if target is TEdit then
Bind(target, 'Value', viewModel, target.Name)
else if target is TLabel then
Bind(target, 'Text', viewModel, target.Name);
end;
end;
end;

function CreateObservable(instance: TObject;
const expression: string): IObservable;

Expand Down

0 comments on commit e4fa8b2

Please sign in to comment.