TMS X-Cloud Todolist with FNC

时间:2023-02-22 12:27:41

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.

TMS X-Cloud Todolist with FNC

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

TMS X-Cloud Todolist with FNC

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. BZOJ1894 : Srm444 avoidfour

    首先只有质数个$4$且个数不超过$10$的限制条件才有用, 也就是长度不能为$44,444,44444,4444444$的倍数. 考虑容斥,计算长度必须是它们$lcm$的倍数,且没有连续$4$个$4$ ...

  2. Android中的dispatchTouchEvent()、onInterceptTouchEvent()和onTouchEvent()

     dispatchTouchEvent (分发TouchEvent) 处理触摸事件分发,事件(多数情况)是从Activity的dispatchTouchEvent开始的.执行super.dispatc ...

  3. (转)MSSQL 各个发行版本版本号以及Compact 版本号

    终于开始写博客了. 不要笑啊. 下面是MSSQL 的发行版本以及版本号.自己整理的. http://support.microsoft.com/kb/321185/zh-cn SQL Server 2 ...

  4. 理解iOS 8中的Self Sizing Cells和Dynamic Type

    http://www.cocoachina.com/ios/20140922/9717.html 在iOS 8中,苹果引入了UITableView的一项新功能--Self Sizing Cells,对 ...

  5. JS链表

    链表 我们可以看到在javascript概念中的队列与栈都是一种特殊的线性表的结构,也是一种比较简单的基于数组的顺序存储结构.由于javascript的解释器针对数组都做了直接的优化,不会存在在很多编 ...

  6. 关于Sublime Text编辑器的实用技巧

    本文转载至一篇博文,为您提供Sublime Text编辑器的12个技巧和诀窍,深入挖掘这个看似简洁的代码编辑器,背后所隐藏的实现各种高级功能的无限可能. 1) 选择 以下是一些Sublime Text ...

  7. 常用vi命令

    i  在当前光标处插入字符,并进入编辑模式 o 在当前光标插入下一行 x 从当前光标处向后删除一个字符. dd 删除当前光标处所在行 :q! 强制退出不保存 :q 退出(文本有改动则警告) :w 保存 ...

  8. 【BZOJ1489】[HNOI2009]双递增序列(动态规划)

    [BZOJ1489][HNOI2009]双递增序列(动态规划) 题面 BZOJ 洛谷 题解 这\(dp\)奇奇怪怪的,设\(f[i][j]\)表示前\(i\)个数中,第一个数列选了\(j\)个数,第二 ...

  9. bootstrap学习笔记(网页开发小知识)

    这是我在学习Boostrap网页开发时遇到的主要知识点: 1.导航条navbar 添加.navbar-fixed-top类可以让导航条固定在顶部,固定的导航条会遮住页面上的其他内容,除非给<bo ...

  10. 破解Aspose 操作pdf word等文档 对10以下版本有效

    using System; using System.IO; namespace LicenseHelper { public static class License { public const ...