TMS X-Cloud Todolist with FNC
Wednesday, June 22, 2016
It's almost three months since we released the first version of the TMS FNC UI Pack, a set of Framework Neutral Components (FNC), and have meanwhile released 2 major updates which include the TTMSFNCTabSet/TTMSFNCPageControl (v1.1), the recently introduced TTMSFNCListBox/TTMSFNCCheckedListBox and significant improvements / new features to the TTMSFNCTreeView such as filtering, sorting, keyboard lookup, clipboard support, ... (v1.2).
As already explained in previous blog posts (http://www.tmssoftware.com/site/blog.asp?post=335 andhttp://tmssoftware.com/site/blog.asp?post=346), the TMS FNC UI Pack is a set of UI controls that can be used from VCL Windows applications, FireMonkey (FMX) Windows, Mac OS-X, iOS, Android applications and LCL framework based Lazarus applications for Windows, Linux, Mac OS-X, ... . The TMS FNC UI Pack contains highly complex & feature-rich components such as grid, planner, rich editor, treeview, toolbars. So, with a single set of controls, you have the freedom of choice to use Delphi, C++Builder or the free Lazarus to create applications for a myriad of operating systems, you have a single learning curve to these components and as demonstrated here, you can use a single source to create apps for multiple targets.
This blog post will cover the TTMSFNCCheckedListBox, which is one of the new components that are added in the latest release (v1.2) of the TMS FNC UI Pack, show how to use myCloudData.net to store data and demonstrate how easy it is to switch between FMX, VCL and LCL with one shared source code. myCloudData is an easy to use & flexible service to make use of structured storage in the cloud from Windows, web, mobile or IoT apps and is offered by tmssoftware.com. myCloudData is OAUTH/JSON REST based and our TMS Cloud Pack includes a component to access the service and thus your data seamlessly.

Click image for more screenshots.
A single shared source
As with our TV-guide sample we have created a single shared source file that is used in a FMX, VCL and LCL project. The unit starts by defining the business logic class that will be instantiated in our application main form unit.
- TTODOListLogic = class
- private
- FTable: TMyCloudDataTable;
- FListBox: TTMSFNCCheckedListBox;
- FMyCloudDataAccess: TMyCloudDataAccess;
- FOnConnected: TNotifyEvent;
- FBitmapContainer: TTMSFNCBitmapContainer;
- protected
- procedure DoConnected(Sender: TObject);
- public
- destructor Destroy; override;
- procedure InitListBox(AListBox: TTMSFNCCheckedListBox);
- procedure InitMyCloudData;
- procedure Refresh;
- procedure InitializeTable;
- procedure AddNewItem(AText: string; ADate: TDateTime; APriority: TPriority);
- procedure DeleteItem;
- procedure Connect;
- procedure DoBeforeDrawItem(Sender: TObject; AGraphics: TTMSFNCGraphics; ARect: TRectF; AItem: TTMSFNCListBoxItem; var AAllow: Boolean; var ADefaultDraw: Boolean);
- procedure DoItemCheckChanged(Sender: TObject; AItem: TTMSFNCCheckedListBoxItem);
- procedure DoItemCompare(Sender: TObject; Item1, Item2: TTMSFNCListBoxItem; var ACompareResult: Integer);
- property OnConnected: TNotifyEvent read FOnConnected write FOnConnected;
- property BitmapContainer: TTMSFNCBitmapContainer read FBitmapContainer write FBitmapContainer;
- end;
Each framework has its own set of units in order to compile succesfully. We use the conditional defines added to our project to make the difference between each framework.
- uses
- Classes, SysUtils, DB
- {$IFDEF VCL}
- ,VCL.TMSFNCListBox, VCL.TMSFNCCheckedListBox, CloudMyCloudData, CloudBase, VCL.TMSFNCUtils,
- CloudCustomMyCloudData, VCL.TMSFNCGraphics, VCL.Dialogs, VCL.TMSFNCTypes, Types, VCL.TMSFNCBitmapContainer;
- {$ENDIF}
- {$IFDEF FMX}
- ,FMX.TMSFNCListBox, FMX.TMSFNCCheckedListBox, FMX.TMSCloudMyCloudData, FMX.TMSCloudBase,
- FMX.TMSFNCUtils, FMX.TMSCloudCustomMyCloudData, FMX.TMSFNCGraphics, FMX.TMSFNCTypes, FMX.Dialogs, Types, FMX.TMSFNCBitmapContainer;
- {$ENDIF}
- {$IFDEF LCL}
- ,LCLTMSFNCListBox, LCLTMSFNCCheckedListBox, LCLTMSCloudMyCloudData, LCLTMSCloudBase,
- LCLTMSFNCUtils, LCLTMSCloudCustomMyCloudData, LCLTMSFNCGraphics, Dialogs, LCLTMSFNCTypes, LCLTMSFNCBitmapContainer;
- {$ENDIF}
myCloudData
As our todolist is storing its todo items in the cloud we take advantage of our own service, that can virtually store anything we want. The initialization is done programmatically.
- procedure TTODOListLogic.InitMyCloudData;
- begin
- FMyCloudDataAccess := TMyCloudDataAccess.Create(nil);
- FMyCloudDataAccess.PersistTokens.Location := plIniFile;
- {$IFDEF FMX}
- FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatafmx.ini';
- FMyCloudDataAccess.OnConnected := DoConnected;
- {$ENDIF}
- {$IFDEF VCL}
- FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatavcl.ini';
- FMyCloudDataAccess.OnConnected := DoConnected;
- {$ENDIF}
- {$IFDEF LCL}
- FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatalcl.ini';
- FMyCloudDataAccess.OnConnected := @DoConnected;
- {$ENDIF}
- FMyCloudDataAccess.PersistTokens.Section := 'tokens';
- FMyCloudDataAccess.App.Key := MYCLOUDDATAKEY;
- FMyCloudDataAccess.App.Secret := MYCLOUDDATASECRET;
- FMyCloudDataAccess.App.CallBackPort := 8888;
- FMyCloudDataAccess.App.CallBackURL := 'http://127.0.0.1:8888';
- end;
You might notice 3 things here. First is the TMyCloudDataAccess class which is common between FMX, VCL and LCL. This is defined earlier in our business logic as the unit names are different for FMX, VCL and LCL.
- type
- {$IFDEF VCL}
- TMyCloudDataAccess = class(TAdvMyCloudData);
- {$ENDIF}
- {$IFDEF FMX}
- TMyCloudDataAccess = class(TTMSFMXCloudMyCloudData);
- {$ENDIF}
- {$IFDEF LCL}
- TMyCloudDataAccess = class(TTMSLCLCloudMyCloudData);
- {$ENDIF}
Second, is the event handler assignment, that we also need to wrap with conditional defines because LCL works with an additional @. Third is the ini file that is also created with a framework suffix, as the token and token encryption are unique per application and not shareable. After defining our business logic, it's time to setup our GUI. The form unit is shared between FMX, VCL and LCL and there you will also notice the uses list and the form file is separated with defines. After designing our form (using the TTMSFNCCheckedListBox, some tool bar buttons (TTMSFNCToolBarButton) we are ready to connect to our business logic and create a working todo list that stores its items in the cloud.
- procedure TTODOListForm.DoConnected(Sender: TObject);
- begin
- Panel1.Enabled := True;
- Panel2.Enabled := True;
- TMSFNCToolBarButton2.Enabled := False;
- TMSFNCCheckedListBox1.Enabled := True;
- TMSFNCToolBarButton4.Enabled := True;
- TMSFNCToolBarButton5.Enabled := True;
- TMSFNCToolBarButton6.Enabled := True;
- TMSFNCToolBarItemPicker1.Enabled := True;
- FTODOListLogic.InitializeTable;
- FTODOListLogic.Refresh;
- end;
- procedure TTODOListForm.FormCreate(Sender: TObject);
- begin
- FTODOListLogic := TTODOListLogic.Create;
- FTODOListLogic.InitListBox(TMSFNCCheckedListBox1);
- FTODOListLogic.InitMyCloudData;
- {$IFDEF LCL}
- FTODOListLogic.OnConnected := @DoConnected;
- {$ELSE}
- FTODOListLogic.OnConnected := DoConnected;
- {$ENDIF}
- TMSFNCCheckedListBox1.BitmapContainer := TMSFNCBitmapContainer1;
- TMSFNCToolBarItemPicker1.BitmapContainer := TMSFNCBitmapContainer1;
- TMSFNCToolBarItemPicker1.Bitmaps.Clear;
- TMSFNCToolBarItemPicker1.Bitmaps.AddBitmapName('low');
- TMSFNCToolBarItemPicker1.DisabledBitmaps.Assign(TMSFNCToolBarItemPicker1.Bitmaps);
- TMSFNCToolBarButton2.DisabledBitmaps.Assign(TMSFNCToolBarButton2.Bitmaps);
- TMSFNCToolBarButton4.DisabledBitmaps.Assign(TMSFNCToolBarButton4.Bitmaps);
- TMSFNCToolBarButton5.DisabledBitmaps.Assign(TMSFNCToolBarButton5.Bitmaps);
- TMSFNCToolBarButton6.DisabledBitmaps.Assign(TMSFNCToolBarButton6.Bitmaps);
- dt := TMyDateTimePicker.Create(Self);
- {$IFDEF FMX}
- dt.Position.X := 5;
- dt.Position.Y := 40;
- {$ELSE}
- dt.Left := 5;
- dt.Top := 40;
- {$ENDIF}
- dt.Date := Now;
- dt.Parent := Panel1;
- dt.Width := 105;
- end;
- procedure TTODOListForm.FormDestroy(Sender: TObject);
- begin
- FTODOListLogic.Free;
- end;
- procedure TTODOListForm.TMSFNCCheckedListBox1ItemSelected(Sender: TObject;
- AItem: TTMSFNCListBoxItem);
- begin
- TMSFNCToolBarButton6.Enabled := True;
- end;
- procedure TTODOListForm.TMSFNCToolBarButton1Click(Sender: TObject);
- begin
- FTODOListLogic.Refresh;
- end;
- procedure TTODOListForm.TMSFNCToolBarButton2Click(Sender: TObject);
- begin
- FTODOListLogic.Connect;
- end;
- procedure TTODOListForm.TMSFNCToolBarButton3Click(Sender: TObject);
- begin
- FTODOListLogic.DeleteItem;
- end;
- procedure TTODOListForm.TMSFNCToolBarButton4Click(Sender: TObject);
- begin
- FTODOListLogic.AddNewItem(Edit1.Text, dt.Date, TPriority(TMSFNCToolBarItemPicker1.SelectedItemIndex));
- end;
- procedure TTODOListForm.TMSFNCToolBarItemPicker1ItemSelected(Sender: TObject;
- AItemIndex: Integer);
- begin
- TMSFNCToolBarItemPicker1.Bitmaps.Clear;
- TMSFNCToolBarItemPicker1.Bitmaps.AddBitmapName(TMSFNCBitmapContainer1.Items[AItemIndex].Name);
- TMSFNCToolBarItemPicker1.DisabledBitmaps.Assign(TMSFNCToolBarItemPicker1.Bitmaps);
- end;
When starting the application, and clicking the connect button, our business logic unit will do the work. It will create a table in myCloudData, send a notification to our GUI, which will then allow to add items to our listbox, refresh or delete existing items, and this is done with one source code, available on multiple frameworks, multiple platforms.
The full source code is available for download

Click image for more screenshots.
Pieter Scheldeman
http://www.tmssoftware.com/site/blog.asp?post=353
TMS X-Cloud Todolist with FNC的更多相关文章
- Everything starts with a dream(A day has only 24 hours and these things take time,所以要抓紧)
There is the famous quote: "Everything starts with a dream" and many years ago, Michael Va ...
- Developing your first FNC custom control
Friday, May 13, 2016 Some weeks ago, we released the TMS FNC UI Pack, a set of Framework Neutral Com ...
- 【Spring Cloud & Alibaba 实战 | 总结篇】Spring Cloud Gateway + Spring Security OAuth2 + JWT 实现微服务统一认证授权和鉴权
一. 前言 hi,大家好~ 好久没更文了,期间主要致力于项目的功能升级和问题修复中,经过一年时间的打磨,[有来]终于迎来v2.0版本,相较于v1.x版本主要完善了OAuth2认证授权.鉴权的逻辑,结合 ...
- On cloud, be cloud native
本来不想起一个英文名,但是想来想去都没能想出一个简洁地表述该意思的中文释义,所以就用了一个英文名称,望见谅. Cloud Native是一个刚刚由VMware所提出一年左右的名词.其表示在设计并实现一 ...
- 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(六)
(六)在Website Cloud中添加site 1新建Website,并打开 使用前面创建的用户 newbee@waplab.com 登录租户Portal,新建一个website 新建完成后, 可以 ...
- 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(五)
(五)注册Website Cloud 1 注册Website Cloud 添加Website Cloud 连接Website Cloud 注意, endpoint 是使用Management Se ...
- 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(四)
(四)搭建Website Cloud环境 1安装CONTROLLER主机 在开始安装Web site Cloud之前,读者应该对该服务的拓扑结构有个大概了解. 如图: Controller是非常重要的 ...
- 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(二)
前言 (二)建立虚拟网络环境,以及域控和DNS服务器 1搭建虚拟网络环境 在Azure上创建虚拟网络.本例选择的是东南亚数据中心.后面在创建虚机的时候,也选择这个数据中心. VNet Name: ...
- spring/spring boot/spring cloud开发总结
背景 针对RPC远程调用,都在使用dubbo.dubbox等,我们也是如此.由于社区暂停维护.应对未来发展,我们准备尝试新技术(或许这时候也不算什么新技术了吧),选择使用了spring ...
随机推荐
- statistics specify some columns count
# -k1 follow the first column nr
- crontab Linux定时器工具
要使用crontab定时器工具,必须要启动cron服务: service cron start crontab的语法,以备日后救急.先上张超给力的图: crontab各参数说明: -e : 执行文字编 ...
- 周末苦逼码代码,为css3的强大所颤抖了
周末小哥我看完了几个星期没追的行尸走肉和生活大爆炸(感谢大A站!),感觉生活真的好空虚,没想到我现在居然会对游戏失去了兴趣!!!代码的魔力真的是无法用语言形容...(我真假...)百无聊赖,在电脑上装 ...
- RobotFramework环境搭建
环境搭建 1. 准备条件 python-2.7.7 https://www.python.org/download/releases/2.7.7/ wxPython2.8-win32-unicode- ...
- Delphi 实现Ini文件参数与TEdit和TCheckBox绑定(TSimpleParam)
在实际工作中,常遇到对Ini参数的修改,显示与保存问题. 如果手工写代码,会有很大的工作量. 本例把ini文件的参数与控件绑定起来,以达到方便使用的目的. 本例程共有2个单元 uSimpleParam ...
- HTTP协议漫谈
简介 园子里已经有不少介绍HTTP的的好文章.对HTTP的一些细节介绍的比较好,所以本篇文章不会对HTTP的细节进行深究,而是从够高和更结构化的角度将HTTP协议的元素进行分类讲解. HTTP的定义和 ...
- tomcat path配置
<pre name="code" class="html">demo:/root# curl http://192.168.32.42:8082/a ...
- DataUml Design 教程6-DataUML Design 1.1版本号正式公布(支持PD数据模型)
从DataUML Design正式公布到如今有两个月了.因为近期比較忙,到如今才公布1.1版本号. 以后本人会一直坚持不断完好DataUML Design软件,希望广大程序员们多多支持. 一.1.1版 ...
- HDU 4937 Lucky Number 规律题_(:зゝ∠)_
把全部合法的进制打出来会发现合法的进制都是在 n/3 n/4 n/5的边上 然后暴力边上的进制数.. #include <cstdio> #include <set> type ...
- Ubuntu启动、停止、重新启动MySQL,查看MySQL错误日志、中文编码错误
1)启动: sudo /etc/init.d/mysql start 2)停止: sudo /etc/init.d/mysql stop 3)重新启动: sudo /etc/init.d/mysql ...