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 ...
随机推荐
- MongoDB 学习小笔记
1.配置:mongod --dbpath=D:\MongoDB\data mongo2.基本的增删查改 find() update()-- 整体更新,局部更新. 修改器: $inc db.person ...
- java 过滤器filter使用案例
主要需要 过滤器类 和配置文件 1.过滤器类 SessionFilter package com.service; import javax.servlet.*; import javax.serv ...
- com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'PDT' is.......
SpringBoot连接数据库的时候报错 java.sql.SQLException: The server time zone value 'PDT' is unrecognized or repr ...
- 在window环境下安装symfony2框架注意事项
首先先放上放上安装的教程:http://www.symfonychina.com/doc/current/setup.html 然后说一下笔者遇到的坑 在运行这条命令的时候,虽然成功下载读取下来了,但 ...
- dedecms织梦无法保存栏目内容的解决方法
最近使用DedeCms5.3和DedeCms5.5遇到了一个不可思议的问题:在添加栏目时IE内核的浏览器无法保存栏目内容.到网上搜索了半天没找到解决方法,查看DedeCms官方搜索到的结果是“栏目内容 ...
- Codeforces 964 等比数列逆元处理 贪心删偶数度节点
A B C 注意sum要在mod范围内 且不能用/a*b来推 #include<bits/stdc++.h> using namespace std; typedef long long ...
- svn 服务器的搭建以及客户端的使用
1.svn 服务器的搭建以及客户端的使用,安装见下面的博客 https://blog.csdn.net/zh123456zh789/article/details/80921179 说明:服务器只是用 ...
- 在vue-cli中使用px2rem,配合lib-flexible使用
原文地址 附上github源码 看这里 1.下载lib-flexible npm安装 npm i lib-flexible --save 2.引入lib-flexible 在main.js中引入li ...
- c# linq 分组groupby
转载: https://www.cnblogs.com/cncc/p/9846390.html 一.先准备要使用的类: 1.Person类: class Person { public string ...
- linux-ntp-10
Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com windows类: time.pool.aliyun.com s1a.time.edu.cn 北京邮电大学 s ...