program LiveBindingProgr;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Bindings.Expression,
System.Bindings.ObjEval,
System.Bindings.Helper;
type
TMyObject1 = class(TObject)
private
FIntegerValue: Integer;
FStringValue: String;
public
property IntegerValue: Integer read FIntegerValue write FIntegerValue;
property StringValue: String read FStringValue write FStringValue;
end;
TMyObject2 = class(TObject)
private
FIntegerValue: Integer;
FStringValue: String;
public
property IntegerValue: Integer read FIntegerValue write FIntegerValue;
property StringValue: String read FStringValue write FStringValue;
end;
TMyResultObject = class(TObject)
private
FIntegerValue: Integer;
FStringValue: String;
public
property IntegerValue: Integer read FIntegerValue write FIntegerValue;
property StringValue: String read FStringValue write FStringValue;
end;
var
MyObject1: TMyObject1;
MyObject2: TMyObject2;
MyResultObject: TMyResultObject;
BindingExpression1: TBindingExpression;
BindingExpression2: TBindingExpression;
begin
MyObject1 := TMyObject1.Create;
MyObject2 := TMyObject2.Create;
MyResultObject := TMyResultObject.Create;
try
MyObject1.IntegerValue := 1;
MyObject1.StringValue := 'LiveBinding ';
MyObject2.IntegerValue := 2;
MyObject2.StringValue := 'power.';
{ a binding expression that binds the two Integer properties of the given objects }
BindingExpression1 := TBindings.CreateManagedBinding(
{ inputs }
[TBindings.CreateAssociationScope([
Associate(MyObject1, 'o1'),
Associate(MyObject2, 'o2')
])],
'o1.IntegerValue + o2.IntegerValue',
{ outputs }
[TBindings.CreateAssociationScope([
Associate(MyResultObject, 'res')
])],
'res.IntegerValue',
nil);
{ a binding expression that binds the two String properties of the given objects }
BindingExpression2 := TBindings.CreateManagedBinding(
{ inputs }
[TBindings.CreateAssociationScope([
Associate(MyObject1, 'o1'),
Associate(MyObject2, 'o2')
])],
'o1.StringValue + o2.StringValue',
{ outputs }
[TBindings.CreateAssociationScope([
Associate(MyResultObject, 'res')
])],
'res.StringValue',
nil);
TBindings.Notify(MyObject1, 'IntegerValue');
TBindings.Notify(MyObject1, 'StringValue');
Writeln('Result of add operation: ', MyResultObject.IntegerValue);
Writeln(MyResultObject.StringValue);
Readln;
finally
MyObject1.Free;
MyObject2.Free;
MyResultObject.Free;
end;
end.
关键词:Tutorial: Using LiveBinding Programatically
824

被折叠的 条评论
为什么被折叠?



