在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在学习 BindingSource 属性时, 可以让两个控件互为绑定源; TBindExpression 对应的功能是 Direction 属性. 先在窗体上添加 Edit1、Edit2、BindingsList1; 然后激活 Edit1、Edit2 和窗体的默认事件. procedure TForm1.FormCreate(Sender: TObject); begin with TBindExpression.Create(BindingsList1) do begin ControlComponent := Edit2; ControlExpression := 'Text'; SourceComponent := Edit1; SourceExpression := 'Text'; // Direction := TExpressionDirection.dirSourceToControl; //默认 // Direction := TExpressionDirection.dirControlToSource; //反向 Direction := TExpressionDirection.dirBidirectional; //双向 Active := True; end; end; procedure TForm1.Edit1Change(Sender: TObject); begin BindingsList1.Notify(Sender, ''); end; procedure TForm1.Edit2Change(Sender: TObject); begin BindingsList1.Notify(Sender, ''); end; 如果没有 Direction 属性, 代码或许会是: procedure TForm1.FormCreate(Sender: TObject); begin with TBindExpression.Create(BindingsList1) do begin ControlComponent := Edit2; ControlExpression := 'Text'; SourceComponent := Edit1; SourceExpression := 'Text'; Active := True; end; with TBindExpression.Create(BindingsList1) do begin ControlComponent := Edit1; ControlExpression := 'Text'; SourceComponent := Edit2; SourceExpression := 'Text'; Active := True; end; end; procedure TForm1.Edit1Change(Sender: TObject); begin BindingsList1.Notify(Sender, ''); end; procedure TForm1.Edit2Change(Sender: TObject); begin BindingsList1.Notify(Sender, ''); end; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论