gpt4 book ai didi

Delphi XE2 和 LiveBindings 控件之间

转载 作者:行者123 更新时间:2023-12-03 14:41:48 27 4
gpt4 key购买 nike

是否可以在控件之间进行 LiveBinding,即获取 2 个编辑框并将其内容添加到一个标签中。我确信是这样,我只是不知道从哪里开始

谢谢

最佳答案

查看示例。 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 属性的下拉菜单,选择“新建实时绑定(bind)...”,选择 TBindExpression
  • 编辑新创建的 BindExpressionLabel11 的属性:将 Caption 分配给 ControlExpression、将 BindScope1 分配给 SourceComponent、将 Edit1.Text + Edit2.Text 分配给 SourceExpression

关于Delphi XE2 和 LiveBindings 控件之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7349340/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com