Android实例-操作sqlite数据库之Grid显示图片(XE8+小米2)

 

结果:

1.数据库文件,记得打包到程序中(assets\internal\)。

 

操作方法:

1.新建firemonkey mobile application
①菜单->File->New->FireMonkey Mobile Application Delphi
②Blank Application
③设置分辨率。
2.增加控件
①拖拽一个FDPhysSQLiteDriverLink1、FDGUIxWaitCursor1、FDConnection1、FDQuery1、Grid1。
3.连接SQLite数据库
①首先用Navicat for SQLite做好一个测试库备用,表中需要有Image字段。
②双击FDConnection1->Definition->Driver ID->SQLite。
③下方的Database设置一下数据库的路径。
④FDQuery1->SQL->输入SQL语句如:“select * from MyTabel”。
⑤FDQuery1->Active->True。
⑥提示输入密码,不用管,直接点OK。
4.绑定数据
①菜单->View->LiveBindings Designer。
②直接用手拖,把FDQuery1与Grid1联上。
5.重要发布
①菜单Project->Deployment->Add File->选择中SQLite数据库。
②Remote Path->assets\internal\。
6.手机程序中加增加的事件
①FDConnection1BeforeConnect事件增加增加代码“FDConnection1.Params.Values['Database']:=TPath.Combine
(TPath.GetDocumentsPath,'test.db');”。
②Button1Click事件下可以写“ FDQuery1.Close; FDQuery1.Open;”。

 

PS:有的人说不清楚在手机上,怎么用IMAGE加载图片。在此补充一下。

procedure TForm1.Button2Click(Sender: TObject);
var
MS: TStream;
begin
with FDQuery1 do
MS := CreateBlobStream(FieldbyName('myimage'), bmRead);
Image1.Bitmap.LoadFromStream(MS);
MS.Free;
end;

 

posted on 2015-09-09 22:00  疯狂delphi  阅读(1163)  评论(1编辑  收藏  举报

导航