VCL

#WEBWONDERS : Making web async easy

Even these Delphi developers who have only set the very first steps into web client development will realize that quite a few important functionalities in web clients are executed only asynchronously by the browser.  Why asynchronous? First of all, why did the creators of browser implement certain functionality only asynchronously? The answer to this question is quite simple. For the developers behind the browser, the user experience comes first and a UI that freezes is a big no-go. At all times, the user interface should remain response. The user should never get the impression that the browser or the machine hangs while navigating on the internet. Now, several operations happening in the browser client application can by nature have a fairly unpredictable time to execute. So, no such function should stop the execution of user interface handling code in the browser.  Traditionally, the browser developers solved this “issue” by JavaScript event handlers that are called asynchronously when the result of a certain operation is ready and meanwhile, any other code can continue to execute. This is no different in TMS WEB Core web client applications written in Object Pascal (but of course compiled to JavaScript by the pas2js compiler). Here, we typically solved this with the Object Pascal event paradigm. When a class instance method is invoked that can only have its result asynchronously, this class instance triggers an event handler when the underlying function completed. When the pas2js compiler also introduced support for anonymous methods, we offered for various such asynchronous operations, anonymous result handlers. To focus on this, let’s take the example of a TWebHttpRequest class. This class permits to invoke HTTP(s) requests from the web client application. Clearly, this is an operation with an unpredictable duration, hence, the result of the request should be asynchronously handled. Classic approaches Example 1: handling via an event: // method starting the HTTP request procedure TForm1.WebButton1Click(Sender: TObject); begin   WebHttpRequest1.URL := ‘https://www.tmssoftware.com/sample.json’;   WebHttpRequest1.Execute(); end; // TWebHTTPRequest event handler for OnResponse procedure TForm1.WebHttpRequest1Response(Sender: TObject; AResponse: string); var jo: TJSONObject; jv: TJSONValue; begin jo := TJSONObject.Create; try jv := jo.ParseJSONValue(AResponse) // do any further processing here on the parsed JSON finally end; end; Example 2: handling via an anonymous method: procedure TForm1.WebButton1Click(Sender: TObject); begin WebHttpRequest1.URL := ‘https://www.tmssoftware.com/sample.json’;WebHttpRequest1.Execute( procedure(AResponse: string; ARequest: TJSXMLHttpRequest) var jo: TJSOBject; jv: TJSONObject; begin jv := TJSONObject.Create; try jv.ParseJSONValue(AResponse); // do any further processing here on the parsed JSON finally end; end); end; Introducing promises Now, while the implementation using anonymous methods probably leads to fairly readable code, imagine needing to handle with multiple HTTP requests that depend on each other, which is in web development a fairly common use-case. While you can in theory invoke another http request from the anonymous method handler that is in turn also handled by a new anonymous method handler, you can see that it quickly becomes clumsy. In the JavaScript world, a more elegant solution was introduced in 2015 with the ES6 standard and by now, any modern browser adopted this and supports it. The good news is that the pas2js v2.0 compiler also embraced and adopted JavaScript promises and offers a Pascal styled equivalent. If you want to read all about JavaScript promises, there are many good resources, but this is a well-written and concise one. In a nutshell, with pas2js […]

Read More

Coming in TMS WEB Core v1.7: Miletus

When it comes to bringing web applications to a desktop enviroment the choice falls on Electron as it’s the most popular framework among web developers. We offer support for Electron applications already, but the downside is always there: it’s a 3rd party solution that we have no control over. At the end of the last year we asked ourselves if we can provide an alternative that fits us better. A few months later here we are about to release a beta version of TMS WEB Core v1.7 with Miletus! What is Miletus exactly? Named after Thales of Miletus, Miletus is a framework that enables TMS WEB Applications to run as desktop applications and it also provides access for native features. In a nutshell, you can fully reuse code created for a web application, take advantage of HTML/CSS for creating a modern & spectacular responsive user interface, access local files & local databases or closely integrate with operating system capabilities and still easily deploy the application as standalone executable. Our colleague Holger Flick explains it in more detail how one could create such Miletus application with TMS WEB Core: Let’s take a look at the available classes, functions and components that will enable you to interact with native operating system functionalities! Classes and functions TMiletusStringList: Read and write local text files. TMiletusBinaryDataStream: Similarly to TMiletusStringList this enables you to write and read local binary files. It also provides multiple formats to access the data. TMiletusClipboard: Read from and write to the OS clipboard. TMiletusShell: Exposes some shell functionalities: open a file with its default application, open an external URL with the default browser, move files to the trash and show files in the containing folder. GetCursorPos: Returns the position of the cursor. GetMiletusPath: Returns the common paths. StartFileDrag: Start dragging a file from your application to any destination where the file is accepted. Components TMiletusOpenDialog: Displays a native open dialog and returns the selected path(s). TMiletusSaveDialog: Similarly to TMiletusOpenDialog, it displays a native save dialog and returns the selected path. TMiletusMessageBox: Shows a native message dialog. The labels, the dialog type, the buttons and the verification checkbox are all customizable. TMiletusErrorBox: Shows a native error message dialog. TMiletusMainMenu: Creates and appends a native main menu to the form where it’s dropped. TMiletusPopupMenu: Creates and displays a native popup menu  TMiletusNotificationCenter: Allows you to show notifications on the operating system.  TMiletusWindow: Allows the creation of multiple application windows which can be linked to forms or other sources. TMiletusTrayIcon: Creates a tray icon on the OS tray. An optional popup menu can be assigned to it. TMiletusFileWatcher: Monitors a list of files for changes. Each file has its own event handler which will be triggered when the file has changed. TMiletusGlobalShortcuts: Add a list of keyboards shortcuts that will be recognized even when the application is not in focus.  What about database support? We also added support for local databases! The component TMiletusClientDataSet makes it easy for a Miletus application to create and use local databases by a familiar syntax of using TClientDataSet. It also allows a seamless integration of multiple types of databases with data-aware components like TWebDBGrid, TWebDBTableControl, TWebDBEdit etc… All the database operations can be done in the standard Delphi way through the TMiletusClientDataSet component.  We prepared 5 database drivers to […]

Read More

Sneak preview of what’s coming in FNC

Intro There are a lot of things going on in the TMS labs at the moment. We announced a lot of great improvements and new features for the upcoming TMS WEB Core 1.7 (https://tmssoftware.com/site/blog.asp?post=772) as well as a couple of past and future platforms FNC runs on (April Fools’ Day joke …). Today we are proud to announce a new platform is coming for FNC. (NOT an April Fools’ Day joke !). Sneak preview Before we want to announce exactly which platform is going to be supported in all it’s glory, here is a sneak preview. What’s coming? FMXLinux official support is coming in the near future! We are currently working hard to make all FNC components compatible with FMXLinux which means there will be a TTMSFNCWebBrowser based on WebKit (https://webkitgtk.org/), a REST based TTMSFNCCloudBase working with Curl (https://curl.se/), PDF export based on our own implementation and much much more! Of course, you can also expect all components that are working based on TMS FNC Core to have FMXLinux support. Stay tuned for more info coming real soon!

Read More

TMS FNC Maps v1.4 released!

What’s new?  The second TMS FNC Maps update of 2021 includes integrated directions for Google Maps and MapKit along with map rotation in TTMSFNCMapKit. Introducing TTMSFNCMapKit A new stand-alone component for Apple MapKit JS is available in TMS FNC Maps v1.4.: TTMSFNCMapKit includes integrated directions and map rotation as component specific features with more to come in the near future. Integrated directions with step by step instructions TTMSFNCGoogleMaps and the new TTMSFNCMapKit component now include support for directions out of the box. All you have to do is drop one component on the form, assign a valid API Key and you’re good to go! Addresses and locations are geocoded automatically and the calculated route is displayed on the map with just a single line of code.     TMSFNCMapKit1.AddDirections(‘New York’, ‘Washington DC’); Optional configuration parameters are available including but not limited to: Polyline color and width Hide markers or polyline or both Indicate if travelling by car or on foot Also, step by step instructions and route details (displayed in the bottom-left corner of the screenshot below) are returned in an event.  Map Rotation Another new feature exclusive to the TTMSFNCMapKit component is the ability to rotate the map programmatically. Again with only one line code the rotation of the map can be changed.   TMSFNCMapKit1.Options.MapRotation := TMSFNCMapKit1.Options.MapRotation + 45; Update Now! Update now to get all the latest and greatest TMS FNC Maps updates and get started exploring the new features!

Read More

Your familiar HotSpot Image comes to the TMS FNC UI Pack v3.3

We have a new major release of the TMS FNC UI Pack, next to some fixes and new features, we have added the TTTMSFNCHotSpotImage to the already extensive set of powerful and feature-rich UI controls that can be used cross framework and cross platform with just one code base. TMS FNC Controls can be simultaneously used on these frameworks: TMS FNC Controls can be simultaneously used on these operating systems/browsers:TMS FNC Controls can be simultaneously used on these IDE’s:   TTMSFNCHotSpotImage This component is already known to VCL and FMX users and for the TMS WEB Core users who don’t know the component, you can compare it with the idea of an Image Map. The TTMSFNCHotSpotImage (further referred to as ‘hotspotimage’) gives you the ability to choose one image and then add different areas (hotspots) with which you can interact and each of them can have their own appearance. TTMSFNCHotSpotImageEditor Our team considers the convenience of visually creating and configuring your components, that is why an editor was created to help you design your hotspots. This can be done in designtime by a double click or right-click on the hotspotimage. To give you full control over your hotspotimage, the editor is also available in runtime. Hotspotimage Demo To let you get more familiar with the component, we have created a demo application that you can find here. This topic describes the steps we have taken to create such a demo application. It is a simple example of a selection game that shows a lot of features. You’ll need to find the correct country for a given capital. The TTMSFNCHotSpotImageEditor (further referred to as ‘hotspotimage editor’) can be used to create the hotspots of the different countries. All of the following can be done in the code as well. But to give an example of the possibilities, we will explain how to this visually. The image can be added in the editor or with the Bitmap property. On the top of the editor there is a toolbar that can be used to create or manipulate the poylgons. Because there is a high contrast and the edgy shape of the different countries, the Magic Wand was the perfect tool to create the polygons. In the panel on the right, you have the buttons ‘Hover’, ‘Selected’ and ‘Down’. With these buttons you can change the appearance for the different states. If none of the hotspots are selected in the listbox, then you are able to change the default appearance used on newly created hotspots in the different pages. On the other hand, if you select a hotspot, you can change the appearance for the specific hotspot. This way, I’ve changed the Fill kind of the polygon to a texture with an image of the flag. You can also change the stroke and font used by the hotspot. To change the name of the different hotspots, select the hotspot in the listbox, edit the text in the edit box and click on the ‘Change Name’ button. Now let’s have a look at the code that is used. Besides the code used to change the settings between game mode and normal selection mode, only two specific events are needed. The event OnSelectedHotSpotChange where the check is added to see if the selection is allowed.As it would not be helpful to unselect a hotspot while playing the game. […]

Read More

Workflow visualization and organization in FMX

Intro The multi-device, true native app platform The FireMonkey® framework is the app development and runtime platform behind RAD Studio, Delphi and C++Builder. FireMonkey is designed for teams building multi-device, true native apps for Windows, OS X, Android and iOS, and getting them to app stores and enterprises fast. source: https://www.embarcadero.com/products/rad-studio/fm-application-platform FMX (FireMonkey) released in 2011 and shortly after we delivered a first set of components. Today, we want to show you the TTMSFNCKanbanBoard component, a highly configurable workflow visualization and organization component. Features Below is a list of the most important features the TTMSFNCKanbanBoard has to offer. The features are not limited to this list, but this will give you a quick insight on what we offer to be able to create an application that visualizes a workflow environment in FireMonkey. Multi collapsible column support Filtering and Sorting Item autosizing HTML formatted text support Collapsible items Database adapter Drag & Drop support Editing support Fully customizable column & item appearance & custom Kanban board item drawing Optional header & footer per column Learn More! Want to learn more about what the TTMSFNCKanbanBoard can do? Here is a video that highlights some of the above features through a demo application. Download & Explore! The TTMSFNCKanbanBoard component is part of the TMS FNC UI Pack, which, on top of FMX, also offers the ability to write your code once and target other frameworks (VCL, LCL and WEB). You can download a full featured trial version of the TMS FNC UI Pack and start exploring the capabilities of the TTMSFNCKanbanBoard component. Coming up The TTMSFNCKanbanBoard is the fourth of a series of components that is covered to empower your FMX (FireMonkey) developments. We started the series with a general overview of the most important components that we have to offer, followed by the TTMSFNCRichEditor, TTMSFNCPlanner and the TTMSFNCTreeView. Next up will be the TTMSFNCGrid, a feature rich and powerful grid component.

Read More

REST API Server with Delphi and XData 5: Read and Watch

TMS XData 5 has been released with lots of new features! Photo by Glenn Carstens-Peters on Unsplash In addition to the recent release of TMS Aurelius 5, a new major version of TMS XData has been also released. TMS XData 5 is the fifth major version of our framework to build multitier applications, including REST API server, and interface-based API client. It makes it easy to build server-side services that reach a broad range of clients, including browsers and mobile devices. Among several features, TMS XData provides: Automatic serialization/deserialization of pure Delphi objects, primitive types, method parameters; Authentication and Authorization; Powerful routing mechanism: route endpoints to methods in your code; Automatic, zero-code Swagger/SwaggerUI support; Interface-based client allows type-safe client applications without additional code; Smooth TMS Aurelius integration allows CRUD endpoints of database entities automatically. The new features released with XData 5 were also antecipated in a previous blog post, The what’s new section in the documentation provides you with a full list, but here we will list a few: Attribute-based Authorization Developers will be able to just add authorization attributes to methods (service operations) or entities (automatic CRUD endpoints) and everything will be applied accordingly. Fine-tuning the protection of your REST API will never be as simple. [Authorize] IDocumentService = interface(IInvokable) procedure Insert(Value: TDoc); [AuthorizeScopes(‘user, editor’)] procedure Modify(Value: TDoc); [AuthorizeScopes(‘admin’)] procedure Delete(DocId: string); [AuthorizeClaims(’email’)] procedure Approve(DocId: string); end; In the example above, all methods (endpoints) require authentication, because the interface has an Authorize attribute that propagates to all methods. So, to invoke Insert, user must be authenticated. Still, to invoke Modify, the user must be authenticated and have either user or editor scope in its credentials. He must be admin to invoke Delete, and finally to approve a document, user must have an email in its claims. It’s also worth noting that the same strategy applies to entities that generate automatic CRUD endpoints: [Entity, Automapping] [EntityAuthorize] [EntityAuthorizeScopes(‘editor’, [TEntitySetPermission.Modify, TEntitySetPermission.Insert])] [EntityAuthorizeScopes(‘admin’, [TEntitySetPermission.Delete])] TCustomer = class {…} public property Id: Integer read FId write FId; property Name: string read FName write FName; end; To access customer endpoints, user must be authenticated. But he must have editor privileges to modify and insert (PUT and POST) and must be admin to invoke DELETE. Easy and straightforward. Async/Await Support in Web Applications TMS XData is smoothly integrated with TMS Web Core, the TMS framework to build web applications. Now your can use async/await mechanism in TXDataWebClient methods that invoke XData server endpoints. As an example, invoking a XData REST API endpoint asynchronously will be as easy as doing this: PendingOrders := await(XClient.List(‘$filter=Status eq pending’)); if PendingOrders.Count = 0 then Exit; // no pending orders to process The single line above will build the HTTP request with proper URL endpoint and HTTP method, invoke it, deserialize the returned JSON into a list of TOrder objects, and all asynchronously! The await function will guarantee that the next line will be executed only after the async execution is executed. Can’t get easier than that. Multitenant Servers This is a feature released with TMS Aurelius, which now has the global filter mechanism, allowing you to build multitenant applications. But XData now includes a few nice mechanisms to integrate with such Aurelius filters that makes building multitenant servers very easily! From a single handler for the event OnManagerCreate, you can […]

Read More

What’s coming in TMS WEB Core v1.7 Ancona

The new version v1.7 of TMS WEB Core has been in development for about 6 months by now. Many of its features were already in development in parallel to v1.6. And yes, our team already is working on v1.8! It will not come as a surprise to you that in v1.7 there are new game-changing features in TMS WEB Core also. Those who have been following the TMS WEB Core development since the first version TMS WEB Core v1.0 Brescia will know that we name the releases after cities along the famous historic race “MilleMiglia”. To be more precise, the legendary race of 1955. And as such, after we visited the city Pesaro with v1.6, for v1.7 we land in Ancona. The historical meaning of the word “Ancona” is elbow which is commonly associated with the shape of the coastline. After the ‘elbow’ Ancona, there are new sights towards the more southern coasts of Italy. Enough history! Let’s bring an overview of what our team has been working on for TMS WEB Core v1.7 Ancona. 1) Components wrapping browser API for local file access The W3C consortium proposed an API forlocal file access from Web browser applications and Google Chrome implements it already. Given that Microsoft uses the Google Chromium engine, it is also available in Microsoft Edge Chromium. With TMS WEB Core, you can take a head start, explore, and start using this with its three components today: TWebLocalTextFile TWebLocalBinaryFile TWebLocalFolder. These components allow you to directly open text and binary files from the local file system as well as traverse the local file system’s folder structure from a Web application. Of course, for security reasons, the users have to give their consent first. 2) Popup menu component and popup menu support in components In TMS WEB Core, we offered the regular TWebMainMenu since its inception and now we completed this trend with the new TWebPopupMenu. It works very similar to a Windows VCL TPopupMenu. Simply drop a TWebPopupMenu on your Web forms and assign it to control.PopupMenu to obtain an automatic context menu for controls. 3) USB device access The times that software developers thought you could never use a Web application for controlling your machine’s hardware are officially over. We already introduced support for Bluetooth with our TWebBluetooth component, and with this release we add two new components TWebUSBSerial and TWebUSBHID that allow you to write applications communicating with locally connected USB devices using a serial protocol or the HID protocol. This opens up a whole new field of applications that can be implemented using Web technologies. 4) TWebStringGrid & TWebDBGrid extensions We added a whole range of new grid features in TWebStringGrid and TWebDBGrid. There are now: Methods to insert & remove rows A range of different inplace editor types Cell merging and cell splitting Loading and saving to streams Loading from a stringlist with CSV data Direct access to grid data as TJSArray Add checkboxes to the grid 5) Async methods There is no way around it in the Web browser, there are different APIs that can only be used in an asynchronous way. The reason for this is very clear: Always guarantee a responsive UI even when lengthy operations are taking place in the application. Many developers struggle with implementing sequential logic for processes […]

Read More

Qualicodex Software: new TMS consulting partner

  We are proud to announce a new collaboration with the team from Qualicodex Software in Brazil to assist users of Delphi in combination with TMS products. From today, Qualicodex Software is our consulting partner for Portuguese and English speaking software developers and software development companies. Ivan Souza is a Software Engineer and a certified Delphi developer since the first version and professor of the Distributed Systems discipline at the West University of Santa Catarina, he started his career in the first versions of Object Pascal, even before Delphi and today he is always looking for updates on new technologies. He worked at Embarcadero Brasil as a Senior Consultant, is an active member of the Delphi community and coordinates the DelphiCodex channel on Youtube. He participated in several conferences and webinars, always providing high quality content to the community. In addition to consulting with Delphi, Ivan also has knowledge and expertise in the technologies that are used by incredible tools, like Web, application servers, databases, distributed systems, IoT, etc. He started his qualification in the tools of tmssoftware with TMS WEB Core, TMS XData and TMS Aurelius. At the moment he is developing an entire ecosystem where these tools are used together with the best in information processing environment (Linux, Desktop, Mobile, Databases, NoSQL, IA, etc …) This partnership is the beginning of a great friendship! Doing it with love, dedication and respect is the secret. Delphi is the key! At the same time, we would like to take the opportunity to mention that we still wish to extend our consulting partner network, foremost in the Asia area, Australia, Canada, South Africa. If you are Delphi developer with TMS component expertise and offering consulting services, get in touch and we will be happy to discuss how we can move forward!

Read More

Lambdas in FlexCel

As you might know, some months ago Microsoft released support for lambda functions in Excel. It was no small change: Lambdas turned the calculation engine into turing-complete, and they can change your spreadsheets in fundamental ways. The main reason why you might want lambdas is that they allow you to define user-defined functions in a spreadsheet, using only other formulas. No VBA or macros required. But Lambda functions are much more: they are real first-class functions that you can pass around. They can even do variable captures like a Lambda in C# or an anonymous method in Delphi. Even with them being only months old, there are a lot of articles and posts about them. So we will not repeat those here, and we will instead focus on a question that we have heard a lot lately: When is FlexCel going to support Lambdas? And the answer is, of course, today. But wait! Let me look at the date… and let me look at the other post today on this site about running FNC in a Sperry Univac Uniscope 200… What can I say? Lambdas weren’t supposed to ship on April 1st; they were supposed to ship weeks ago. But we kept finding small stuff to polish. As it is usual in FlexCel development, we wanted to cover all cases that we could and make sure everything worked as it should. And as it is usual too, we were late and I am writing this post in April 1st. You can download FlexCel 7.9 on our site, and start adding lambdas and lets everywhere. Just the usual advice: “With great power comes great responsibility”. As powerful as they are, it is simple to abuse them and end up with spreadsheets only a mother could love. Or understand. I’ve already seen pages-long lambdas written in many places, and one has to wonder how you are supposed to debug those formulas once something goes wrong. Right now, Excel tools for debugging lambdas are quite poor. Tales from the trenches Following a one post tradition, I am reviving the “tales from the trenches” section for this post. This is the section where I write about small details we find in our daily development. Of course, every day has a different tale, so I’ve chosen one at random to close this entry. Schrödinger parameter names. When we wrote the validation code for parameter names, we assumed that they would follow the same rules as Excel names. In particular, you can’t have a name that is also a valid cell reference. So you can’t have a name named “A1” or “R1C1”. You can’t either name a name “R” or “C” since that means “Full Row” and “Full Column” in R1C1 notation. But, while you can’t name a parameter “A1”, you can name it “C”. So how does this work? How does Excel know that when I write “=Sum(C)” I refer to the parameter C and not to the entire column? The only way to find out was to try it, so I set the reference mode in Excel to R1C1, and went to write the formula `=Lambda(C,Sum(C))` It gave an error of invalid name. So I tried now with `=Lambda(A1,Sum(A1))`, and Excel happily accepted it. Valid parameter names depend on the reference mode you are […]

Read More