控件之间的Delphi XE2和LiveBindings

前端之家收集整理的这篇文章主要介绍了控件之间的Delphi XE2和LiveBindings前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以在控件之间进行活动绑定,即取两个编辑框,并将其内容一起添加标签中.我确定是,我只是不知道从哪里开始

谢谢

解决方法

看看样品. 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)上放置两个编辑(Edit1,Edit2),一个标签(Label1)和一个TBindScope(BindScope1).>为两个编辑的OnChange事件(EditChange)创建事件处理程序.>选择Label1,展开LiveBindings属性的下拉菜单,选择’New Live Binding …’,选择TBindExpression>编辑新创建的BindExpressionLabel11的属性:将Caption分配给ControlExpression,将BindScope1分配给SourceComponent,Edit1.Text Edit2.Text to SourceExpression

原文链接:https://www.f2er.com/delphi/101509.html

猜你在找的Delphi相关文章