是否可以在兩個控件之間進行LiveBinding,即獲取2個編輯框並獲得將其內容添加到標籤中的結果。我敢肯定,這是,我只是不知道從哪裏開始控件之間的Delphi XE2和LiveBindings
感謝
是否可以在兩個控件之間進行LiveBinding,即獲取2個編輯框並獲得將其內容添加到標籤中的結果。我敢肯定,這是,我只是不知道從哪裏開始控件之間的Delphi XE2和LiveBindings
感謝
看看樣品。 SVN庫網址:https://radstudiodemos.svn.sourceforge.net/svnroot/radstudiodemos/branches/RadStudio_XE2/LiveBindings
一個例子:
----- ----- Unit1.dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 286
ClientWidth = 426
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 62
Width = 48
Height = 13
Caption = 'Edit1Edit2'
end
object Edit1: TEdit
Left = 8
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
OnChange = EditChange
end
object Edit2: TEdit
Left = 8
Top = 35
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'
OnChange = EditChange
end
object BindingsList1: TBindingsList
Methods = <>
OutputConverters = <>
UseAppManager = True
Left = 20
Top = 5
object BindExpressionLabel11: TBindExpression
Category = 'Binding Expressions'
ControlComponent = Label1
SourceComponent = BindScope1
SourceExpression = 'Edit1.Text + Edit2.Text'
ControlExpression = 'Caption'
NotifyOutputs = False
Direction = dirSourceToControl
end
end
object BindScope1: TBindScope
Left = 192
Top = 16
end
end
----- ----- Unit1.pas
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.Bind.EngExt, Vcl.Bind.DBEngExt,
System.Rtti, System.Bindings.Outputs, Vcl.Bind.Editors, Data.Bind.Components,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
BindingsList1: TBindingsList;
BindExpressionLabel11: TBindExpression;
BindScope1: TBindScope;
procedure EditChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
System.Bindings.Helper;
procedure TForm1.EditChange(Sender: TObject);
begin
TBindings.Notify(Sender, 'Text');
end;
end.
如何使用IDE設計產生的結果:
在(默認)示例項目的位置:
C:\Users\Public\Documents\RAD Studio\9.0\Samples\Delphi\LiveBinding\Components\bindexpression\fmx\BindExpressionSampleProject.dproj
不正是。
不完全是,它顯示了一個源和一個控件組件之間的簡單綁定。要在單個表達式中涉及兩個不同的源組件,我相信您需要TBindScope組件來解析Edit1和Edit2引用。您也可以將Form1分配給SourceComponent,但這是使用全局變量Form1的所有後果。 –
請注意,這些演示(LiveBindings的)只能通過ESD安裝。 ISO映像不包含它們;如果你是從ISO安裝的,你必須去他的回答中提供的鏈接TOndrej。 –
@KenWhite - 演示也可以通過Subversion鏈接下載:http://sourceforge.net/projects/radstudiodemos/ –
你不需要TBindScope將組件綁定在一起。假設你在表單上有edit1和edit2。如果您將edit2 BindingSource設置爲edit1,則它將鏈接到edit1的更改
他在詢問有關將2個組件的屬性添加在一起的問題。你的答案似乎是將一個組件的屬性分配給另一個組件。 – chuacw
這看起來很棒。 SourceExpression ='Edit1.Text + Edit2.Text''如何編譯,評估或者其他什麼? –
@David:有一個涉及到的整個運行時(可擴展)表達式評估引擎。 –
哦,聽起來很刺激! –