// 在构造函数里创建绑定对象
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
// 创建绑定集合列表
BindingsList1 = new TBindingsList(this);
// 建立单向绑定并激活
TBindExpression * BindExpress1 = new TBindExpression(BindingsList1);BindExpress1->ControlComponent = Label1; // 目标控件
BindExpress1->ControlExpression = "Text"; // 目标控件属性
BindExpress1->SourceComponent = TrackBar1; // 源控件
BindExpress1->SourceExpression = "Format(\"进度: %.0f%%\", Value)"; // 源控件属性
BindExpress1->Active = true; // 激活, Active = false 是断开绑定
// 建立双向绑定并激活
TBindExpression * BindExpress2 = new TBindExpression(BindingsList1);
BindExpress2->ControlComponent = Edit1; // 目标控件
BindExpress2->ControlExpression = "Text"; // 目标控件属性
BindExpress2->SourceComponent = TrackBar2; // 源控件
BindExpress2->SourceExpression = "Value"; // 源控件属性
BindExpress2->Direction = TExpressionDirection::dirBidirectional; // 双向绑定
BindExpress2->Active = true; // 激活, Active = false 是断开绑定
}
// 动态更新第1个表达式的数据
void __fastcall TForm1::TrackBar1Change(TObject *Sender)
{
BindingsList1->Notify(Sender, "Value");
}
// 动态更新第1个表达式的数据
void __fastcall TForm1::TrackBar2Change(TObject *Sender)
{
BindingsList1->Notify(Sender, "Value");
}
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
BindingsList1->Notify(Sender, "");
}