10

コントロール間でLiveBindingを実行することは可能ですか。つまり、2つの編集ボックスを使用して、それらのコンテンツをラベルに追加した結果を取得できますか。確かに、どこから始めればいいのかわからない

ありがとう

4

3 に答える 3

9

サンプルをご覧ください。SVNリポジトリのURL: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デザイナを使用して結果を生成する方法:

  • フォーム(Form1)に2つの編集(Edit1、Edit2)、ラベル(Label1)とTBindScope(BindScope1)を配置します。
  • 両方の編集のOnChangeイベント(EditChange)のイベントハンドラーを作成します。
  • Label1を選択し、LiveBindingsプロパティのドロップダウンを展開し、[New Live Binding ...]を選択して、TBindExpressionを選択します。
  • 新しく作成されたBindExpressionLabel11のプロパティを編集します。CaptionをControlExpressionに、BindScope1をSourceComponentに、Edit1.Text+Edit2.TextをSourceExpressionに割り当てます。
于 2011-09-08T16:18:14.233 に答える
4

次の(デフォルト)場所にあるサンプルプロジェクト:

C:\Users\Public\Documents\RAD Studio\9.0\Samples\Delphi\LiveBinding\Components\bindexpression\fmx\BindExpressionSampleProject.dproj

正確にそれを行います。

于 2011-09-08T16:09:19.843 に答える
-1

コンポーネントをバインドするためにTBindScopeを実行する必要はありません。フォームにedit1とedit2があるとします。edit2 BindingSourceをedit1に設定すると、edit1への変更へのリンクになります

于 2012-01-15T22:15:32.420 に答える