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 ...
随机推荐
- Wiki 安装部署
#首先登陆进入 MySQL 数据库 [root@oldboy tools]# mysql -uroot -poldboy123 #创建一个 wiki 是库 mysql> create datab ...
- 转载:PHP编程规范
PHP-FIG 在说啥是PSR-[0-4]规范的之前,我觉得我们有必要说下它的发明者和规范者:PHP-FIG,它的网站是:www.php-fig.org.就是这个联盟组织发明和创造了PSR-[0-4] ...
- python openpyxl 简单使用
1. 加载excel import openpyxl from openpyxl.utils import get_column_letter,column_index_from_string fro ...
- Maven私服仓库
Maven私服仓库 现象:在maven install的时候,会做以下事情 [INFO] Installing /Users/cqq/Documents/VanDreamPro/vandream-er ...
- Python开发WebService--使用soaplib库
Python开发WebService--使用soaplib库 使用soaplib开发基于Python语言的WebService主要有以下四个步骤:一.准备环境 S1:下载插件Python.s ...
- Tomcat网站上的core和deployer的区别
8.5.13 Please see the README file for packaging information. It explains what every distribution(分布) ...
- Vue全局混入
混入 (mixins) 是一种分发 Vue 组件中可复用功能的非常灵活的方式.混入对象可以包含任意组件选项.当组件使用混入对象时,所有混入对象的选项将被混入该组件本身的选项. 数据对象合并 数据对象在 ...
- win10激活方法 windows 10 最简单的激活方法
1.首先,要用管理员权限打开cmd命令行窗口,可以搜索框中输入“cmd”,在出现的“命令行提示符”,图标上右击“以管理员身份运行”. 2.为了让其它激活工具的密钥清除,先卸载密钥,在命令行输入 ...
- javascript(腾讯)
var a={key:"1",value:2}; war b=a; b.value+=a.key, 打印b.value是多少,a.value呢? 答案:都是21.因为javascr ...
- 【NOIP2012模拟11.1】塔(加强)
题目 玩完骰子游戏之后,你已经不满足于骰子游戏了,你要玩更高级的游戏. 今天你瞄准了下述的好玩的游戏: 首先是主角:塔.你有N座塔一列排开.每座塔各自有高度,有可能相等. 这个游戏就不需要地图了. 你 ...