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.

  1. TTODOListLogic = class
  2. private
  3. FTable: TMyCloudDataTable;
  4. FListBox: TTMSFNCCheckedListBox;
  5. FMyCloudDataAccess: TMyCloudDataAccess;
  6. FOnConnected: TNotifyEvent;
  7. FBitmapContainer: TTMSFNCBitmapContainer;
  8. protected
  9. procedure DoConnected(Sender: TObject);
  10. public
  11. destructor Destroy; override;
  12. procedure InitListBox(AListBox: TTMSFNCCheckedListBox);
  13. procedure InitMyCloudData;
  14. procedure Refresh;
  15. procedure InitializeTable;
  16. procedure AddNewItem(AText: string; ADate: TDateTime; APriority: TPriority);
  17. procedure DeleteItem;
  18. procedure Connect;
  19. procedure DoBeforeDrawItem(Sender: TObject; AGraphics: TTMSFNCGraphics; ARect: TRectF; AItem: TTMSFNCListBoxItem; var AAllow: Boolean; var ADefaultDraw: Boolean);
  20. procedure DoItemCheckChanged(Sender: TObject; AItem: TTMSFNCCheckedListBoxItem);
  21. procedure DoItemCompare(Sender: TObject; Item1, Item2: TTMSFNCListBoxItem; var ACompareResult: Integer);
  22. property OnConnected: TNotifyEvent read FOnConnected write FOnConnected;
  23. property BitmapContainer: TTMSFNCBitmapContainer read FBitmapContainer write FBitmapContainer;
  24. 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.

  1. uses
  2. Classes, SysUtils, DB
  3. {$IFDEF VCL}
  4. ,VCL.TMSFNCListBox, VCL.TMSFNCCheckedListBox, CloudMyCloudData, CloudBase, VCL.TMSFNCUtils,
  5. CloudCustomMyCloudData, VCL.TMSFNCGraphics, VCL.Dialogs, VCL.TMSFNCTypes, Types, VCL.TMSFNCBitmapContainer;
  6. {$ENDIF}
  7. {$IFDEF FMX}
  8. ,FMX.TMSFNCListBox, FMX.TMSFNCCheckedListBox, FMX.TMSCloudMyCloudData, FMX.TMSCloudBase,
  9. FMX.TMSFNCUtils, FMX.TMSCloudCustomMyCloudData, FMX.TMSFNCGraphics, FMX.TMSFNCTypes, FMX.Dialogs, Types, FMX.TMSFNCBitmapContainer;
  10. {$ENDIF}
  11. {$IFDEF LCL}
  12. ,LCLTMSFNCListBox, LCLTMSFNCCheckedListBox, LCLTMSCloudMyCloudData, LCLTMSCloudBase,
  13. LCLTMSFNCUtils, LCLTMSCloudCustomMyCloudData, LCLTMSFNCGraphics, Dialogs, LCLTMSFNCTypes, LCLTMSFNCBitmapContainer;
  14. {$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.

  1. procedure TTODOListLogic.InitMyCloudData;
  2. begin
  3. FMyCloudDataAccess := TMyCloudDataAccess.Create(nil);
  4. FMyCloudDataAccess.PersistTokens.Location := plIniFile;
  5. {$IFDEF FMX}
  6. FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatafmx.ini';
  7. FMyCloudDataAccess.OnConnected := DoConnected;
  8. {$ENDIF}
  9. {$IFDEF VCL}
  10. FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatavcl.ini';
  11. FMyCloudDataAccess.OnConnected := DoConnected;
  12. {$ENDIF}
  13. {$IFDEF LCL}
  14. FMyCloudDataAccess.PersistTokens.Key := TTMSFNCUtils.GetDocumentsPath + PthDel + 'myclouddatalcl.ini';
  15. FMyCloudDataAccess.OnConnected := @DoConnected;
  16. {$ENDIF}
  17. FMyCloudDataAccess.PersistTokens.Section := 'tokens';
  18. FMyCloudDataAccess.App.Key := MYCLOUDDATAKEY;
  19. FMyCloudDataAccess.App.Secret := MYCLOUDDATASECRET;
  20. FMyCloudDataAccess.App.CallBackPort := 8888;
  21. FMyCloudDataAccess.App.CallBackURL := 'http://127.0.0.1:8888';
  22. 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.

  1. type
  2. {$IFDEF VCL}
  3. TMyCloudDataAccess = class(TAdvMyCloudData);
  4. {$ENDIF}
  5. {$IFDEF FMX}
  6. TMyCloudDataAccess = class(TTMSFMXCloudMyCloudData);
  7. {$ENDIF}
  8. {$IFDEF LCL}
  9. TMyCloudDataAccess = class(TTMSLCLCloudMyCloudData);
  10. {$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.

  1. procedure TTODOListForm.DoConnected(Sender: TObject);
  2. begin
  3. Panel1.Enabled := True;
  4. Panel2.Enabled := True;
  5. TMSFNCToolBarButton2.Enabled := False;
  6. TMSFNCCheckedListBox1.Enabled := True;
  7. TMSFNCToolBarButton4.Enabled := True;
  8. TMSFNCToolBarButton5.Enabled := True;
  9. TMSFNCToolBarButton6.Enabled := True;
  10. TMSFNCToolBarItemPicker1.Enabled := True;
  11. FTODOListLogic.InitializeTable;
  12. FTODOListLogic.Refresh;
  13. end;
  14. procedure TTODOListForm.FormCreate(Sender: TObject);
  15. begin
  16. FTODOListLogic := TTODOListLogic.Create;
  17. FTODOListLogic.InitListBox(TMSFNCCheckedListBox1);
  18. FTODOListLogic.InitMyCloudData;
  19. {$IFDEF LCL}
  20. FTODOListLogic.OnConnected := @DoConnected;
  21. {$ELSE}
  22. FTODOListLogic.OnConnected := DoConnected;
  23. {$ENDIF}
  24. TMSFNCCheckedListBox1.BitmapContainer := TMSFNCBitmapContainer1;
  25. TMSFNCToolBarItemPicker1.BitmapContainer := TMSFNCBitmapContainer1;
  26. TMSFNCToolBarItemPicker1.Bitmaps.Clear;
  27. TMSFNCToolBarItemPicker1.Bitmaps.AddBitmapName('low');
  28. TMSFNCToolBarItemPicker1.DisabledBitmaps.Assign(TMSFNCToolBarItemPicker1.Bitmaps);
  29. TMSFNCToolBarButton2.DisabledBitmaps.Assign(TMSFNCToolBarButton2.Bitmaps);
  30. TMSFNCToolBarButton4.DisabledBitmaps.Assign(TMSFNCToolBarButton4.Bitmaps);
  31. TMSFNCToolBarButton5.DisabledBitmaps.Assign(TMSFNCToolBarButton5.Bitmaps);
  32. TMSFNCToolBarButton6.DisabledBitmaps.Assign(TMSFNCToolBarButton6.Bitmaps);
  33. dt := TMyDateTimePicker.Create(Self);
  34. {$IFDEF FMX}
  35. dt.Position.X := 5;
  36. dt.Position.Y := 40;
  37. {$ELSE}
  38. dt.Left := 5;
  39. dt.Top := 40;
  40. {$ENDIF}
  41. dt.Date := Now;
  42. dt.Parent := Panel1;
  43. dt.Width := 105;
  44. end;
  45. procedure TTODOListForm.FormDestroy(Sender: TObject);
  46. begin
  47. FTODOListLogic.Free;
  48. end;
  49. procedure TTODOListForm.TMSFNCCheckedListBox1ItemSelected(Sender: TObject;
  50. AItem: TTMSFNCListBoxItem);
  51. begin
  52. TMSFNCToolBarButton6.Enabled := True;
  53. end;
  54. procedure TTODOListForm.TMSFNCToolBarButton1Click(Sender: TObject);
  55. begin
  56. FTODOListLogic.Refresh;
  57. end;
  58. procedure TTODOListForm.TMSFNCToolBarButton2Click(Sender: TObject);
  59. begin
  60. FTODOListLogic.Connect;
  61. end;
  62. procedure TTODOListForm.TMSFNCToolBarButton3Click(Sender: TObject);
  63. begin
  64. FTODOListLogic.DeleteItem;
  65. end;
  66. procedure TTODOListForm.TMSFNCToolBarButton4Click(Sender: TObject);
  67. begin
  68. FTODOListLogic.AddNewItem(Edit1.Text, dt.Date, TPriority(TMSFNCToolBarItemPicker1.SelectedItemIndex));
  69. end;
  70. procedure TTODOListForm.TMSFNCToolBarItemPicker1ItemSelected(Sender: TObject;
  71. AItemIndex: Integer);
  72. begin
  73. TMSFNCToolBarItemPicker1.Bitmaps.Clear;
  74. TMSFNCToolBarItemPicker1.Bitmaps.AddBitmapName(TMSFNCBitmapContainer1.Items[AItemIndex].Name);
  75. TMSFNCToolBarItemPicker1.DisabledBitmaps.Assign(TMSFNCToolBarItemPicker1.Bitmaps);
  76. 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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 【Spring Cloud & Alibaba 实战 | 总结篇】Spring Cloud Gateway + Spring Security OAuth2 + JWT 实现微服务统一认证授权和鉴权

    一. 前言 hi,大家好~ 好久没更文了,期间主要致力于项目的功能升级和问题修复中,经过一年时间的打磨,[有来]终于迎来v2.0版本,相较于v1.x版本主要完善了OAuth2认证授权.鉴权的逻辑,结合 ...

  4. On cloud, be cloud native

    本来不想起一个英文名,但是想来想去都没能想出一个简洁地表述该意思的中文释义,所以就用了一个英文名称,望见谅. Cloud Native是一个刚刚由VMware所提出一年左右的名词.其表示在设计并实现一 ...

  5. 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(六)

    (六)在Website Cloud中添加site 1新建Website,并打开 使用前面创建的用户 newbee@waplab.com 登录租户Portal,新建一个website 新建完成后, 可以 ...

  6. 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(五)

    (五)注册Website Cloud 1 注册Website Cloud 添加Website Cloud   连接Website Cloud 注意, endpoint 是使用Management Se ...

  7. 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(四)

    (四)搭建Website Cloud环境 1安装CONTROLLER主机 在开始安装Web site Cloud之前,读者应该对该服务的拓扑结构有个大概了解. 如图: Controller是非常重要的 ...

  8. 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(二)

    前言 (二)建立虚拟网络环境,以及域控和DNS服务器   1搭建虚拟网络环境 在Azure上创建虚拟网络.本例选择的是东南亚数据中心.后面在创建虚机的时候,也选择这个数据中心. VNet Name: ...

  9. spring/spring boot/spring cloud开发总结

    背景        针对RPC远程调用,都在使用dubbo.dubbox等,我们也是如此.由于社区暂停维护.应对未来发展,我们准备尝试新技术(或许这时候也不算什么新技术了吧),选择使用了spring ...

随机推荐

  1. C++中联合体(union)的使用

    typedef union para { ]; struct { double a; double b; double c; double d; }NP; }NPara; //或者如下所示 union ...

  2. lightoj 1030

    递推,倒着递推. #include<stdio.h> #define maxn 1010 #define min(a,b) (a)>(b)?(b):(a) int main() { ...

  3. [置顶] woff格式字体怎么打开和编辑?

    如题! woff百度百科:http://baike.baidu.com/link?url=toS7yqpN9VlEcO2GOEp5JEA9-TeaZgIdVqTOv7iHshsNvk-V8HtxEY0 ...

  4. nodeJs入门笔记(二)

    js中window通常是全局变量 global 是node.js里的全局变量 node中能访问的对象一般都是 global的 属性 global 对象属性 process 用于描述当前Node 进程状 ...

  5. Why Study JavaScript?

    JavaScript is one of the 3 languages all web developers must learn: 1. HTML to define the content of ...

  6. Internet设置->连接选项卡->局域网(LAN)设置 某些设置由系统管理员进行管理

    今天突然发现ss不能使用了.经过一系列排查发现 Internet设置->连接选项卡->局域网(LAN)设置 某些设置由系统管理员进行管理,如上图. 修改注册表值HKEY_LOCAL_MAC ...

  7. Oracle EBS-SQL (GL-4):从接收追溯到接收事务

    SELECT row_id, creation_date, created_by, last_update_date, last_updated_by,last_update_login, note_ ...

  8. linux关闭防火墙方法

    在关闭防火墙之前需要查看防火墙的状态,可以使用service iptables status命令来查看,确定防火墙是否开启再来进行关闭操作. 如果想临时开启防火墙使用命令service iptable ...

  9. poj2636---Electrical Outlets(插线板)

    #include <stdio.h> #include <stdlib.h> int main() { int n,nc,i; scanf("%d",&am ...

  10. Android NDK 编译FFmpeg(不需要复杂的环境变量设置)

    环境: CentOS6.2——64位 借鉴:https://vec.io/posts/how-to-build-ffmpeg-with-android-ndk 在根目录下创建work文件夹:cd  / ...