Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库
先在窗体上放置控件:
DataSource1 : TDataSource;
ClientDataSet1 : TClientDataSet;
Label1 : TLabel;
Edit1 : TEdit;
Memo1 : TMemo;
ImageControl1 : TImageControl;
BindNavigator1 : TBindNavigator; {在连接过程中, 会自动添加下面部件}
BindingsList1 : TBindingsList;
BindScopeDB1 : TBindScopeDB; DBLinkLabel1SpeciesNo1 : TBindDBTextLink;
DBLinkEdit1Category1 : TBindDBEditLink;
DBLinkMemo1Notes1 : TBindDBMemoLink;
DBLinkImageControl1Graphic1 : TBindDBImageLink;
测试使用官方提供的测试数据 biolife.xml(或 biolife.cds), 其路径通常是: C:\Program Files\Common Files\CodeGear Shared\Data\biolife.xml
连接步骤:
、置 DataSource1 的 DataSet 属性为 ClientDataSet1; 、置 ClientDataSet 的 FileName 属性为 'C:\Program Files\Common Files\CodeGear Shared\Data\biolife.xml'; 、将四个控件分别关联到 biolife.xml 中的字段:
Label1 -> 右键 -> Link To DB Field... -> 选择 Species No (数字)
Edit1 -> 右键 -> Link To DB Field... -> 选择 CateGory (string)
Memo1 -> 右键 -> Link To DB Field... -> 选择 Notes (Text)
ImageControl -> 右键 -> Link To DB Field... -> 选择 Graphic (Graphics) 、置 BindNavigator1 的 BindScope 属性为 BindScopeDB1; 、置 ClientDataSet1 的 Active 属性为 True.
二、运行时连接:
先在窗体上放置控件(其它在运行时完成):
DataSource1 : TDataSource;
ClientDataSet1 : TClientDataSet;
Label1 : TLabel;
Edit1 : TEdit;
Memo1 : TMemo;
ImageControl1 : TImageControl;
BindNavigator1 : TBindNavigator;
BindingsList1 : TBindingsList;
BindScopeDB1 : TBindScopeDB;
与设计时功能相同的代码:
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDataSet1.FileName := 'C:\Program Files\Common Files\CodeGear Shared\Data\biolife.xml';
DataSource1.DataSet := ClientDataSet1;
BindScopeDB1.DataSource := DataSource1;
BindNavigator1.BindScope := BindScopeDB1; with TBindDBTextLink.Create(BindingsList1) do
begin
ControlComponent := Label1;
DataSource := BindScopeDB1;
FieldName := 'Species No';
end; with TBindDBEditLink.Create(BindingsList1) do
begin
ControlComponent := Edit1;
DataSource := BindScopeDB1;
FieldName := 'Category';
end; with TBindDBMemoLink.Create(BindingsList1) do
begin
ControlComponent := Memo1;
DataSource := BindScopeDB1;
FieldName := 'Notes';
end; with TBindDBImageLink.Create(BindingsList1) do
begin
ControlComponent := ImageControl1;
DataSource := BindScopeDB1;
FieldName := 'Graphic';
end; ClientDataSet1.Active := True;
end;
要绑定到 TStringGrid, 在设计时(在上面的基础上)只需: StringGrid1 -> Link to DB DataSource... -> BindScopeDB1
下面是运行时绑定到 TStringGrid 的代码:
uses Fmx.Bind.Editors, Data.Bind.DBLinks, Fmx.Bind.DBLinks; procedure TForm1.FormCreate(Sender: TObject);
begin
ClientDataSet1.FileName := 'C:\Program Files\Common Files\CodeGear Shared\Data\biolife.xml';
DataSource1.DataSet := ClientDataSet1;
BindScopeDB1.DataSource := DataSource1;
BindNavigator1.BindScope := BindScopeDB1;
ClientDataSet1.Active := True; with TBindDBGridLink.Create(BindingsList1) do //还可用 TBindGridLink
begin
GridControl := StringGrid1;
DataSource := BindScopeDB1;
Active := True;
end;
end;
Delphi XE2 之 FireMonkey 入门(31) - 数据绑定: 绑定数据库的更多相关文章
- Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件
Delphi XE2 之 FireMonkey 入门(30) - 数据绑定: TBindingsList: TBindExpression 的 OnAssigningValue 事件 表达式中的函数有 ...
- Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法
Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法 TBindingsList 中可能不止一个表达式, 通 ...
- Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope
Delphi XE2 之 FireMonkey 入门(27) - 数据绑定: TBindingsList: TBindScope 如果在编写表达式时, 如果能够随意指认需要的控件就好了(通过 Owne ...
- Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems
Delphi XE2 之 FireMonkey 入门(26) - 数据绑定: TBindingsList: TBindExprItems 如果要给一对 "源控件" 和 " ...
- Delphi XE2 之 FireMonkey 入门(25) - 数据绑定: TBindingsList: 表达式的灵活性及表达式函数
Delphi XE2 之 FireMonkey 入门(25) - 数据绑定: TBindingsList: 表达式的灵活性及表达式函数 绑定表达式中可以有简单的运算和字符串连接, 但字符串需放在双引号 ...
- Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList、TBindPosition [未完成...]
Delphi XE2 之 FireMonkey 入门(32) - 数据绑定: TBindingsList: TBindList.TBindPosition [未完成...] //待补...
- Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText()、CheckedState()
Delphi XE2 之 FireMonkey 入门(28) - 数据绑定: TBindingsList: 表达式函数测试: SelectedText().CheckedState() 示例构想: 用 ...
- Delphi XE2 之 FireMonkey 入门(22) - 数据绑定: BindingSource、BindingName、FindBinding()、Binding[]
在窗体上添加 TrackBar1.Edit1.Label1, 然后设置属性(可在设计时): procedure TForm1.FormCreate(Sender: TObject); begin ...
- Delphi XE2 之 FireMonkey 入门(24) - 数据绑定: TBindingsList: TBindExpression.Direction
在学习 BindingSource 属性时, 可以让两个控件互为绑定源; TBindExpression 对应的功能是 Direction 属性. 先在窗体上添加 Edit1.Edit2.Bindin ...
随机推荐
- redis常见问题和解决方案
转载:https://www.cnblogs.com/aspirant/p/6820262.html [原创]那些年用过的Redis集群架构(含面试解析) redis常见问题和解决方案 持久化.主从问 ...
- LDP - Linux文档工程的简介,包括帮助,向导和文档
总览 SYNOPSIS Linux文档工程(LDP)为Linux社区提供多种自由文档资源,包括向导 (guide),常见问答 (FAQ),入门 (HOWTO) 以及手册页 (man-pages). 作 ...
- 这样讲 SpringBoot 自动配置原理,你应该能明白了吧
https://juejin.im/post/5ce5effb6fb9a07f0b039a14 前言 小伙伴们是否想起曾经被 SSM 整合支配的恐惧?相信很多小伙伴都是有过这样的经历的,一大堆配置问题 ...
- Python Requests库 Get和Post的区别和Http常见状态码
(1) 在客户端,Get方式在通过URL提交数据,数据在URL中可以看到:POST方式,数据放置在HTML HEADER内提交. (2) GET方式提交的数据最多只能有1024 Byte,而P ...
- 安装BCG界面库 会导致vs2013qt库配置消失
安装BCG界面库 会导致vs2013qt库配置消失 安装BCG界面库 会导致vs2013qt库配置消失 安装BCG界面库 会导致vs2013qt库配置消失
- centos7使用cron任务的相关命令(与centos6有区别)
一.cron任务的自启动相关命令 1.检测cron定时服务是否自启用 systemctl is-enabled crond.service 结果展示如下: enable表示已启用自启动 disable ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(1)|开篇]
今天我们来开一个新系列. 从零学习rustlang. 简单介绍下rustlang: Rust 是一门系统级编程语言,被设计为保证内存和线程安全,防止段错误产生.作为系统级编程语言,它的基本理念是 “零 ...
- 如何将vim打造成Linux下的source insight
编写者:龙诗科 邮箱:longshike2010@163.com 2016-01-06 众所周知,windows下的source insight是阅读项目代码的神器,其神奇之处在于可以根据当前鼠标所指 ...
- 更新Navicat Premium 后打开数据库出现1146 - Table 'performance_schema.session_variables' doesn't exist
更新Navicat Premium 后打开数据库出现1146 - Table 'performance_schema.session_variables' doesn't exist 解决方法:打开终 ...
- Python 3标准库课件第一章(第二版)
第一章文本1.1 string:文本常量和模板1.2 textwrap:格式化文本段落1.3 re:正则表达式1.4 difflib:比较序列str类,string.Templatetextwrap ...