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.

view plain text

  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.

view plain text

  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.

view plain text

  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.

view plain text

  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.

view plain text

  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

时间: 2024-12-17 20:39:38

TMS X-Cloud Todolist with FNC的相关文章

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 Components (FNC), i.e. UI controls that can be used from VCL Windows applications, FireMonkey (FMX) Windows, Mac OS-X, iOS, Android applications and LCL

Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]56528192: startup date [Tue Sep 19 15:05:24 CST 2017]; root of context hierarchy 2017-09-19 15:05:24.858 INFO 9986 --

笔记:Spring Cloud Zuul 快速入门

Spring Cloud Zuul 实现了路由规则与实例的维护问题,通过 Spring Cloud Eureka 进行整合,将自身注册为 Eureka 服务治理下的应用,同时从 Eureka 中获取了所有其他微服务的实例信息,这样的设计非常巧妙的将服务治理体系中维护的实例信息利用起来,使得维护服务实例的工作交给了服务治理框架自动完成,而对路由规则的维护,默认会将通过以服务名作为 ContextPath 的方式来创建路由映射,也可以做一些特别的配置,对于签名校验.登录校验等在微服务架构中的冗余问题

笔记:Spring Cloud Feign 其他配置

请求压缩 Spring Cloud Feign 支持对请求与响应进行GZIP压缩,以减少通信过程中的性能损耗,我们只需要通过下面二个参数设置,就能开启请求与响应的压缩功能,yml配置格式如下: feign: compression: request: enabled: true response: enabled: true 同时,我们还能对请求压缩做一些更细致的设置,比如指定压缩的请求数据类型,并设置了请求压缩的大小下限,只有超过这个大小的请求才会对其进行压缩,示例如下: feign: com

Spring Cloud官方文档中文版-服务发现:Eureka服务端

官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR3/#spring-cloud-eureka-server 文中例子我做了一些测试在:http://git.oschina.net/dreamingodd/spring-cloud-preparation Service Discovery: Eureka Server 服务发现:Eureka服务端 How to Include Eureka Server 如何创建Eurek

【推介】TMS的控件之“TMS Unicode Component Pack”和“TMS Advanced Toolbars & Menus”

TMS Unicode Component Pack是一款支持多语言的界面控件包,提供超过60种控件来为你的Delphi和C++Builder应用程序添加Unicode支持. 介绍: TMS Unicode Component Pack控制组件能让你在不终止Delphi.C++Builder或Windows 95/98/ME的情况下利用Windows NT/2000/XP/2003/Vista的Unicode功能开发应用程序.  注意:这些控制组件不会将Unicode功能添加到Windows 9

Azure云平台学习之路(三)——Cloud Services

1.什么是云服务? 能够部署高度可用的且可无限缩放的应用程序和API.简而言之,就是你写的CMD程序按照一定的框架进行少量修改就能运行在Azure云平台上. 2.Azure云服务有什么特点? (1)专注应用程序而不是硬件,PaaS的一种. (2)支持多种框架和语言. (3)集成了运行状况监视和负载平衡. (4)自动缩放优化成本和性能 3.建立云服务之前,我们需要建立一个云存储,来记录我们的程序的日志信息(当然,这不是必须的) (1)选择左边导航栏的"存储".主面板上显示的是所有已有的存

【云迁移论文笔记】Cloud Migration Research:A Systematic Review

Cloud Migration Research:A Systematic Review Author Info: Pooyan Jamshidi PhD Postdoctoral Researcher Dublin City University· School of Computing Major: model-driven software architecture evolution PS: This paper is the first SLR(Systematic Literatur

记录一个 spring cloud 配置中心的坑,命令行端口参数无效,被覆盖

spring cloud 配置中心 结合GIT , 可以运行时更新配置文件.发送指令让应用重新读取配置文件. 最近在测试服务器实现了一套,结果CPU 实用率暴增,使用docker compose启动 restart always 多节点的服务一直重启关闭重启关闭. 日志文件记录了一个异常: 国内国外搜了一遍都没有解决 org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean wit