Quantcast
Channel: TMS Software
Viewing all 1006 articles
Browse latest View live

TMS WEB Core v1.6 beta brings the pas2js v2.0 quantum leap

$
0
0

The past couple of months and especially weeks have been a nerve-racking ride! Nerve-racking because the scope of introducing the new pas2js v2.0 compiler in TMS WEB Core is huge. Our code library that works with TMS WEB Core and the pas2js compiler meanwhile got huge, so there is a lot of testing and polishing involved to ensure everything continues to work smoothly with the new compiler. But also nerve-racking because the new compiler offers so many exciting features we are eager to take advantage of.
But well, we think we have reached the level of stability where we can offer a beta release for our TMS WEB Core users that should work smooth out of the box and ready to take advantage of the new amazing features!

The new pas2js v2.0 compiler is nothing short of amazing and a quantum leap forward for Object Pascal developers to tackle the most challenging rich web client application developments! And it is not just the compiler itself, it is of course also the supporting RTL for features such as generics. What an honor and experience to work so closely together with the two masterminds of the project Mattias Gaertner and Michael Van Canneyt to bring TMS WEB Core with pas2js v2.0 to life. The list of new features in the pas2js v2.0 compiler is long and can be consulted in detail here but let me highlight the major new capabilities:

  • Generics
  • Attributes
  • Class constructors
  • Resource strings
  • Async procedure decorator
  • Await support
  • JavaScript promises support
Best of all, we expect the introduction of this huge step forward to be smooth. All our demos for example continue to work without changing any line of code. Unless you did perhaps very specific things directly with underlying JavaScript objects or event handlers, the new version should be fully backwards compatible.

Before moving to a final release of TMS WEB Core v1.6.0.0, we want to give you, users of TMS ALL-ACCESS or TMS WEB Core sufficient time to test the new version, give your feedback, address issues in case these would arise. You can find the beta download now on the "My Products" page on your account on our website. This beta version can be used from Delphi XE7 to Delphi 10.4 Sydney as well as Lazarus 2.0.10.

At the same time our team is feverishly working on bringing the pas2js v2.0 compiler also to TMS WEB Core for Visual Studio Code. The challenge is even bigger here as we need to test and validate everything on 3 different operating systems as you can use TMS WEB Core for Visual Studio Code directly on Windows, macOS and Linux to build Object Pascal based web client applications. Expect also here that a beta will follow shortly!

Oh, and by the way, TMS WEB Core v1.6 will be get the name Pesaro. Pesaro is the town along the legendary Mille Miglia 1955 race after Rimini that was the name of version v1.5. So, our race with TMS WEB Core enjoys the beautiful scenery of Pesaro.




TMS WEB Core v1.6 beta in a nutshell (video)

$
0
0

Yesterday we announced the beta release for TMS WEB Core v1.6 Pesaro.
Before moving to a final release of TMS WEB Core v1.6.0.0, we want to give our registered TMS ALL-ACCESS and TMS WEB Core users sufficient time to test the new version. Registered users can find the beta download now on the "My Products" page on our website. This beta version can be used from Delphi XE7 to Delphi 10.4 Sydney as well as Lazarus 2.0.10.

At the same time our team is also working on bringing the pas2js v2.0 compiler to TMS WEB Core for Visual Studio Code.

The stunning new pas2js v2.0 features are not only coming in Delphi but also in Visual Studio Code. Watch our colleague Holger Flick show the use of generics in a TMS WEB Core application in an internal beta of TMS WEB Core for Visual Studio Code that will soon also be coming to you.



Dali’s words: “Have no fear of perfection, you will never reach it” are the motivating force and inspiration behind everything we do. So, here we literally follow up the video about generics in TMS WEB Core with code improvement suggestions that bring it one step closer to perfection: enumerators.



Stay tuned for more updates!

We welcome Abatic, consulting partner for Spanish TMS/Delphi users

$
0
0



We are proud to announce a new collaboration with the team from Abatic in Spain to assist users of Delphi in combination with TMS products. From today, Abatic is our consulting partner for Spanish speaking software developers and software development companies in Spain and Colombia. With our partners we aim to have experts nearby, in the same timezone and speaking the native language of our customers to help with consulting services. This can range from assisting with:

  • designing software architectures
  • choosing the best components for a task
  • developing projects or parts of projects or
  • adding resources to help with developing projects
  • offering training in specific TMS products
We are glad to start this partnership with Abatic as we are convinced their high expertise will offer excellent services for you. The team consists of 6 professionals including two Embarcadero MVP's: Emilio Pérez and Jhonny Suárez.

Emilio Pérez

Jhonny Suárez

Abatic is also an early adaptor of TMS WEB Core and in particular TMS WEB Core for Visual Studio Code and is even offering a training course and an ebook for it:



Among the broad expertise of the Abatic team are:
  • Delphi Developer Certified
  • 2 Embarcadero MVP consultants in team
  • WEB Core web applications
  • VCL Windows applications
  • FMX cross-platform applications
  • Multi-tier database development
  • XData REST server + Aurelius ORM
  • On-site training / WEB Core training course
  • MySQL developer Certified
  • PostgreSQL DBA Certified
  • RAD Server
We are convinced this will strengthen the adoption of Delphi, of our components and will lead to better, richer and more sophisticated Delphi applications with TMS compoonents or web applications based on the TMS WEB Core framework. With the Abatic team closely in touch with Spanish speaking developers, our team will have the opportunity to closely listen to the feedback and wishes of the Spanish speaking community and steer our developments according to these needs.

If you are not Spanish speaking, don't worry, our consulting partner network is growing and feel free to have a look at the partner directory and get in touch and have a chat how they can help you.

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!

TMS FNC Maps: Small update with big improvements

$
0
0

Intro

With the release of TMS WEB Core v1.6 beta yesterday (https://tmssoftware.com/site/blog.asp?post=717), we bring a whole set of new and exciting compiler features such as generics, attributes and many more. Please read the blog and start exploring the new features. The beta of TMS WEB Core v1.6 is available as a download on the My Products page.

Today, we released all of our FNC products with some core improvements, ready to be used in combination with TMS WEB Core v1.6. On top of that, TMS FNC Maps has been released with 3 new features.

Tile Layers

TTMSFNCOpenLayers now supports adding tile layers in the XYZ format. To demonstrate this, we generated a free API key from the following service: https://www.thunderforest.com. This service offers a great set of high quality layers that can be used in combination with our TTMSFNCOpenLayers implementation. To add a layer we used the following code:
procedure TForm1.AddLayer;
begin
  TMSFNCOpenLayers1.AddTileLayer('https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=[INSERT API KEY]');
end;
With the following result:



Save coordinate data to GPX

The update also brings a way to save your coordinate data to a GPX file. To implement this, use one of the following overloads
procedure SaveToGPXStream(ACoordinates: TTMSFNCMapsCoordinateRecArray; AStream: TStream);
procedure SaveToGPXStream(ACoordinates: TTMSFNCMapsCoordinateRecArray; AStream: TStream; AMetaData: TTMSFNCMapsGPXMetaData);
procedure SaveToGPXFile(ACoordinates: TTMSFNCMapsCoordinateRecArray; AFileName: string);
procedure SaveToGPXFile(ACoordinates: TTMSFNCMapsCoordinateRecArray; AFileName: string; AMetaData: TTMSFNCMapsGPXMetaData);
function SaveToGPXText(ACoordinates: TTMSFNCMapsCoordinateRecArray): string;
function SaveToGPXText(ACoordinates: TTMSFNCMapsCoordinateRecArray; AMetaData: TTMSFNCMapsGPXMetaData): string;;

The TTMSFNCMapsGPXMetaData record currently allows specifying the following GPX attributes

  • AuthorName
  • AuthorLink
  • TrackName
  • TrackType

Plus Codes



Plus Codes are like street addresses for people or places that don’t have one. Instead of addresses with street names and numbers, Plus Codes are based on latitude and longitude, and displayed as numbers and letters. With a Plus Code, people can receive deliveries, access emergency and social services, or just help other people find them.
source: https://maps.google.com/pluscodes/

TMS FNC Maps supports Plus Codes encoding & decoding with the TTMSFNCMapsPlusCode class (available in the *.TMSFNCMapsCommonTypes unit). To get started, and convert an existing coordinate to a Plus Code, use the following code:
procedure TForm1.EncodeCoordinate;
var
  p: string;
begin
  p := TTMSFNCMapsPlusCode.Encode(CreateCoordinate(40.689188, -74.044562));
  //p = '87G7MXQ4+M5'
end;
To decode a Plus Code to a coordinate, the Decode function can be used:
procedure TForm1.DecodePlusCode;
var
  c: TTMSFNCMapsCoordinateRec;
begin
  c := TTMSFNCMapsPlusCode.Decode(87G7MXQ4+M5);
  //c = 40.689188, -74.044562;
end;

Update Now!

Update now to get all the latest and greatest FNC updates and get started exploring the new features of TMS WEB Core 1.6!

TMS FlexCel academic license

$
0
0



Even in this challenging times we want to make our contribution to the Delphi community and most importantly to the aspiring future Delphi developer and hereby encouraging next generations of enthusiast Delphi developers.
In 2020 we have launched our TMS Academic Program and added so far 3 products. Today, we extend the TMS Academic Program with a 4th product : TMS FlexCel for VCL & FMX.
With the Delphi Academic edition, students already have an extremely powerful tool in their hands and we want to enrich this with offering our most popular products also free to students with the TMS Academic Program.

FlexCel for VCL / FireMonkey is a suite of Delphi components allowing to manipulate Excel files or generate Excel template based reports. It includes an extensive API allowing to natively read/write Excel files. If you need to read or create complex spreadsheets, on Windows or macOS on machines without Excel installed, Flexcel can do the job.
This academic license can be used with Delphi 10.4, just like our other 3 academic licenses!

Supported frameworks:




Visit the landing page and discover more about our TMS Academic Program.

Getting started :

  1. Register for a free TMS FlexCel Academic license with a school or university email address

  2. Receive your credentials to login on our website via your student email address

  3. Login and download your free TMS FlexCel Academic installer

  4. Install the product for the Delphi Community Edition

  5. Enjoy being part of the TMS family with full access to our website, TMS support center, product updates for 1 year and develop great Delphi VCL applications

Get started with TMS software today and secure your place for the future in the Delphi world!
TMS FlexCel for VCL & FMX is out last addition to our Academic Program for 2020! Of course, we plan to extend this academic program in 2021. We are curious to know how the TMS Academic Program helped you so far in achieving exciting software development challenges and we are eager to learn what next TMS products you would wish to see in the academic program.




TMS WEB Core for Visual Studio Code 1.2beta introducing the pas2js v2.0RC compiler!

$
0
0



A bit more than a week ago, we made the first beta available of TMS WEB Core for Delphi v1.6beta Pesaro that introduces the new v2.0 pas2js compiler and extended RTL.

For those who missed it, the new version v2.0 of the compiler is a quantum leap forward and its main new features are:

  • Generics
  • Attributes
  • Class constructors
  • Resource strings
  • Async procedure decorator
  • Await support
  • JavaScript promises support

Read all about pas2js v2.0 and TMS WEB Core for Delphi v1.6 beta in this blog article.

As expected, we have now a first beta of TMS WEB Core for Visual Studio Code ready for TMS ALL-ACCESS and TMS WEB Core for Visual Studio Code customers.

With TMS WEB Core for Visual Studio Code you can:

  • Use the free IDE loved by web developers on Windows, macOS or Linux
  • Use your favorite fully object-oriented, type-safe Object Pascal language
  • Take advantage of a large eco-system of web developer friendly tools in the IDE
  • Use a fast RAD component based development approach
  • See your app in the IDE using live WYSIWYG web technology based form designer
  • Create classic web client applications
  • Develop installable PWA's on mobile devices as well as desktop Chromium based browser
  • Build cross platform desktop applications with modern looking web based UIs on Windows, macOS & Linux via Electron

Our team is looking forward to all your feedback, wishes and suggestions for improvements and future developments!


Live data and live a bootstrap theme used in the form designer in Visual Studio Code

Live Google Maps in the form designer in Visual Studio Code

Debugging a TMS WEB Core application directly from the Visual Studio Code IDE

XMAS special just for YOU!

$
0
0



TMS is celebrating XMAS together with DelphiStyles! With great pleasure we announce a great collaboration with DelphiStyles!. Delphistyles provide high quality FireMonkey multiplatform style templates and VCL styles.

DelphiStyles team is a compact development studio. They have an expertise in app development with Delphi since version #1 through all generations to the last release. Their mission is to let Delphi developers build Windows/macOS/iOS/Android applications with great and modern UI.

Special offer for YOU!

Get the free "DelphiStyles: Collection of FM Multiplatform and VCL style templates for Bitmap Style Designer", when purchasing a new TMS ALL-ACCESS license!

So don't waste your time and order your TMS ALL-ACCESS license today and receive the DelphiStyles bundle for free. You get all current styles and all styles in the future for free and for life (to the value of 249 US dollars).

FNC empowers your FMX (FireMonkey) development

$
0
0

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. Through the years we learned and evolved our FMX support and translated that knowledge into new major components:

  • Grid
  • Planner
  • Treeview
  • Chart
  • Kanban Board
  • Pickers & Selectors
  • Rich Editor
  • ...

All of these components fully adopted the FMX (FireMonkey) framework. In 2016 we even went a step further and introduced FNC. FNC boosts your FMX development and offers a single code base to re-use in other frameworks as well: VCL, WEB (TMS WEB Core) and LCL (Lazarus).

To the point

How FNC empowers your FMX development is nicely demonstrated and explained by Holger Flick in the following video. He explains the various components available for the FMX framework, how to use them and what they can do for your application.



Get started!

Get started exploring FMX and what FNC can mean for your FMX development: http://fnc.tmssoftware.com. Already using FNC? Let us know in the comments.


This was 2020 at TMS

$
0
0



There is a lot to say about this year 2020 and for sure, we at TMS had our challenges as well. But to end the year and look back at it, we prefer to stick to the positive things that happened this year.

New products

Looking back, it is actually amazing how many product releases we did and what significant new products were introduced. I think like most software developers, you can relate to the feeling how sometimes painfully slow and difficult software development can be. But in hindsight, we can look back at fantastic achievements. It is with this feeling I'm looking back at our year 2020 especially about two new products that were released:

TMS FNC Maps

We took our FNC concept on steroids with this new product. TMS FNC Maps is not only supporting 4 different development frameworks, 5 operating systems, all major browsers but also 8 different mapping services. Take the best mapping features at the best prices and combine these to integrate powerful mapping functionality in your VCL, FMX, LCL and TMS WEB Core web applications.

TMS WEB Core for Visual Studio Code

Another tour de force was bringing our TMS WEB Core framework to Visual Studio Code. Visual Studio Code is like a natural fit for TMS WEB Core. It is the beloved IDE for web developers, it runs on Windows, macOS and Linux, it is built with web technology, it has a large ecosystem and it is free. It foremostly enables to render your pages and its controls live in the designer, even taking responsive design in account. We even released already a major update in 2020 with support for PWA and Electron cross-platform desktop application development support. Upcoming is the release of v1.2 with support for pas2js v2.0 compiler that introduces generics, attributes, await, promises and many more new capabilities.

Product updates

Many products got constant updates mainly driven by your feedback, needs, requests. There are too many updates in 2020 to cover all in detail but I'd like to highlight a few ones that personally excited me.

TMS Flexcel

TMS Flexcel for VCL/FMX and TMS Flexcel for .NET got frequent updates this year. The major new features that were added are support for .NET Core v5.0 and an API for adding charts to .XLSX files.

TMS VCL UI Pack

Formerly known as TMS Component Pack, TMS VCL UI Pack has an almost bi-weekly update scheme. Countless new features and enhancements were added all the time. But for me, the major one is the introduction of the new TAdvWebBrowser component that is a wrapper for the new Windows Edge Chromium browser. TAdvWebBrowser permits modern and secure integration of web functionality in your VCL applications. Further, we focused a lot on polishing VCL styles support, TMS styles support and multi-monitor high-DPI support.

TMS FNC UI Pack

Be it for cross-platform FireMonkey applications, VCL Windows applications, TMS WEB Core web applications or free Lazarus IDE based cross-platform applications, TMS FNC UI Pack is a bundle of UI controls including grid, planner, rich editor, treeview, object inspector, ... and much more.

Several new components were added to this pack this year: TTMSFNCWaitingIndicator, TTMSFNCSplitter, TTMSFNCRating, TTMSFNCRichEditorHorizontalRuler, TTMSFNCProgressBar and also here our cross-framework, cross-platform browser component was updated to Edge Chromium on the Windows platform. We also introduced FNC styles, to enable easily to give applications built with FNC UI controls a modern Microsoft Office or Microsoft Windows like look & feel.

TMS WEB Core

Two major releases of TMS WEB Core were done, TMS WEB Core v1.4 Ravenna and TMS WEB Core v1.5 Rimini bringing heaps of new functionality.

  • New UI components: TWebImageSlider, TWebContinuousScroll, TWebShare, TWebToast
  • New UI logic capabilities: TWebElementActionList, automatic theme adaption, Sentry based cloud exception logging
  • New support for DB backends: RAD server, FaunaDB, Dream Factory: TWebRadServerClientDataset, TWebDreamFactoryClientDataSet, TWebFaunaDBClientDataSet
  • New IDE integration: live preview, HTML template import
  • New direct local database access in Electron apps: mySQL and PostgreSQL


RAD Studio 10.4 support added

This year, Embarcadero released RAD Studio 10.4, so of course, we ensured that every product works seamlessly and as fast as possible with the newest IDE.

TMS Business Subscription

The suite of products to create powerful backends was non-stop improved and extended. TMS XData swagger support was enhanced and it got flexible URL routing mechanism using Route attribute. TMS Logging got support for the Linux platform and new logging output handlers. TMS RemoteDB got support for native database-access drivers, making you no longer depend on FireDac, UniDac or other drivers and have faster operation.

TMS Cryptography Pack

We delivered also here in 2020 several new cryptography functionality: New TLSH component for comparing files based on hashes, new key import from PEM files in TECCEncSign & TRSAEncSign, new signature algorithm on elliptic curve ed448.

Web site enhancements



We launched the TMS Support Center this year, replacing the old support forum. The TMS Support Center offers better search, better interface for editing posts, adding attachments to post, direct messages, ... resulting in a much better experience for consulting our support. And best of all, we were able to import our old support forum information in the new TMS Support Center so no valuable information got lost.

We also overhauled the "My Products" page on our website. It became faster and gives you a more focused view on your active versus expired products, offers to renew and status of active licenses.

Academic program launch



We launched this year our TMS Academic Program. Its goal is to enable students to get the maximum out of Delphi and become a new generation of passionate Delphi developers this way. An academic version of the product is free and fully functional and supports the latest Delphi IDE. The program was started this year and we already brought academic versions of 4 of our major products: TMS VCL UI Pack, TMS FNC UI Pack, TMS WEB Core and TMS Flexcel for VCL/FMX.

Books



Four (yes 4!) books were released this year. It started in March with TMS WEB Core Webanwendungen mit Delphi entwickeln written by our chief evangelist Holger Flick and was followed quickly by the English version TMS WEB Core: Web Application Development with Delphi. These books get you started either in German language or English language to develop full web applications with TMS WEB Core clients and TMS XData based backends.

Later in the year, a first book in a series "Hands-on with Delphi", the book "TMS Software Hands-on with Delphi: Cross-platform Multi-tiered Database Applications: Web and Desktop Clients, REST/JSON Server, and Reporting" was released. The goal of the hands-on series is to cover how different TMS products combined with Delphi fit together with real-life examples. In the first hands-on book, TMS FNC UI Pack controls, TMS Cryptography Pack, TMS Flexcel, TMS Aurelius ORM & TMS XData, TMS WEB Core are all used together.

And if that was not enough, even the 2nd in the series TMS Software Hands-on with Delphi was released: FNC Maps: Cross-framework, Cross-platform, Cross-service Mapping Component Library. This book mainly covers the new TMS FNC Maps product but brings TMS FNC UI Pack, TMS WEB Core, TMS Flexcel, TMS XData, TMS Cryptography Pack in the mix.

Celebrations



This year 2020, there was not only the celebration of 25 years Delphi in February but also 20 years founding of the company tmssoftware.com BV in October.

Consulting partners



This year, we also extended our family of partners around the world assisting Delphi developers to get the most out of Delphi in combination with TMS products. We welcome this year Thierry Laborde, offering consulting on Delphi & TMS products for the French speaking developer community and the company Abatic in Spain for the Spanish speaking Delphi developers. In addition to our existing partners, they can give you a helping hand in the most challenging parts of your software development with Delphi and our products.

Videos

Not only did our chief evangelist Holger Flick add numerous videos on our YouTube channel, in July our colleague Gjalt also started a new series Gjalt's 101. With this new series, Gjalt brings you the latest news about what is cooking in our labs and tips & tricks to get the most out of our components.

2021 ...

The new year is a white page. There is already lots in the pipeline, exciting R&D work that will come soon to existing and new products, new services we will bring and there are even more ideas and dreams. We are ready to make 2021 an exciting year for Delphi developers! We will share information about upcoming developments soon. We are foremost interested in hearing what your ideas, wishes, needs and dreams are, so our team efforts can maximally aligned to these!

Best wishes for a happy & healthy 2021!

Show a PDF from a TMS WEB Core app

$
0
0



This is a frequently asked question from TMS WEB Core users how a PDF file, typically a generated report, can be shown from a TMS WEB Core app. The good news is that it is simple as browser technology has us covered. There are basically two options:

  1. Show the PDF file in a new browser window (tab)
  2. Show the PDF embedded in the application window

So, let's just do this and provide a project that shows this. To show the PDF file in a new browser window, all we need to do is call Application.Navigate(URL, ntBlank), where URL is the link to the PDF file.

To show the PDF file embedded in the application window, we can drop a TWebBrowserControl on the form and set its URL to the link to the PDF file.


So, in a nutshell, the code behind becomes as simple as:

procedure TForm2.WebButton1Click(Sender: TObject);
const
  URL = 'https://download.tmssoftware.com/download/manuals/TMS%20Async.pdf';
begin
  if WebRadioButton1.Checked then
    WebBrowserControl1.URL := URL
  else
    Application.Navigate(URL, TNavigationTarget.ntBlank);
end;

For your convenience, you can download the test project here

Needless to say that this exact code works in TMS WEB Core for Delphi, TMS WEB Core for Lazarus and TMS WEB Core for Visual Studio Code. It can be applied in a classic web client application, a PWA and also an Electron based cross-platform desktop application.

Not using TMS WEB Core yet? Get your free & fully functional trial version download from our website and benefit from the Holiday Season holidays to explore and get excited.

TMS WEB Core v1.6 released

$
0
0



We're thrilled to bring the quantum leap the pas2js v2.0 compiler brings to TMS WEB Core with the release of TMS WEB Core v1.6 Pesaro today. The new compiler has been in development for quite some time and brings the experience for Object Pascal developers to create web client applications from the Delphi or Lazarus IDE to a new level. Among the major new capabilities of the pas2js compiler are:

  • Generics
  • Attributes
  • Class constructors
  • Resource strings
  • Async procedure decorator
  • Await support
  • JavaScript promises support
  • Resource file support
In a nutshell, this ensures you can bring your modern Object Pascal code to the web as well as take advantage directly from Object Pascal code from modern typical web paradigms such as await & promises for handling asynchronous code.

All active registered users for TMS WEB Core can obtain the update after login on our website under "My Products". Just as our team internally can now start taking advantage of the new compiler features to write new & enhanced framework code, you can apply this to your application level code. The new compiler features will also enable more of other TMS products that were already using generics and attributes for example to become a possible target for porting this to TMS WEB Core.

TMS FNC Products ready for the new TMS WEB Core

Note also that our entire TMS FNC components portfolio has already been prepared for compatibility with TMS WEB Core v1.6. The amazing array of cross-framework, cross-platform components from TMS FNC UI Pack, TMS FNC Chart, TMS FNC Cloud Pack, TMS FNC Maps, TMS FNC Blox, TMS FNC Dashboard Pack is ready for use in your web client applications now.

Coming soon to Visual Studio Code

As the same compiler and exactly the same framework code is used in TMS WEB Core for Visual Studio Code, you can expect shortly the release of TMS WEB Core for Visual Studio Code v1.2 that will bring all these enhancements to the Visual Studio Code IDE running directly on Windows, macOS or Linux.

It doesn't end here, it just continues

With the new TMS WEB Core release, the path is now also open to start introducing new functionality and features at framework level. Our team has been very busy in parallel to develop new extensions to the framework, so, be assured that TMS WEB Core v1.7 is already in the pipeline. More about what is cooking in the labs for v1.7 will be detailed in the coming weeks.

Get started now

If you didn't get your feet wet already with RAD component based Object Pascal based web client development, now is the time to enter this fast moving & fascinating world. The sheer amount of new possibilities and territories is staggering. You cannot only develop no-deployment cross platform rich web client applications, but also offline usable and installable PWA's for use on mobile devices bypassing Apple or Google stores. Or you can use the Electron framework to create cross-platform desktop applications for Windows, macOS and Linux with a modern and fresh looking HTML/Web based GUI. And know that we have even more and exciting alternative targets for TMS WEB Core web client applications in the making!

Learn here about the new generics support:



Get the TMS WEB Core v1.6 trial or use TMS WEB Core v1.6 as part of the TMS ALL-ACCESS subscription, the no-nonsense subscription to our entire product portfolio coupled with priority technical support services.

These are exciting times for Delphi, Lazarus or Object Pascal developers in general!



WYSIWYG rich text editing in FMX

$
0
0

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 TTMSFNCRichEditor component, a light-weight WYSIWYG editor for formatted text.



Features

Below is a list of the most important features the TTMSFNCRichEditor 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 edit and format rich text content in FireMonkey.

  • Formatted text with bullets, hyperlinks, images, indenting and aligned paragraphs
  • Functions for merging, highlighting text, undo/redo and clipboard operations
  • Horizontal ruler support
  • Stores its text natively in the .RTE file format
  • Possibilities to load from .TXT, .RTF, .HTML and .RTE
  • Export to .PDF, .TXT, .RTF, .HTML and .RTE
  • Separate rich editing/formatting toolbars
  • Emoticons support
  • Support for BitmapContainer images
  • Autocorrect: custom auto-correct actions
  • Interface to TMS Spell Check engine



Learn More!

Want to learn more about what the TTMSFNCRichEditor can do? Here is a video that highlights some of the above features through a demo application.



Download & Explore!

The TTMSFNCRichEditor 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 TTMSFNCRichEditor component.

Coming up

The TTMSFNCRichEditor is the first 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. Next up will be the TTMSFNCPlanner component, a highly configurable planner / scheduler component for FMX (FireMonkey), so stay tuned for more!.

TMS VCL UI Pack v10.5 released

$
0
0



The New Year 2021 is still fresh and there is already a major update for TMS VCL UI Pack. As always, our updates focus on bringing the latest improvements and adding features to make your VCL Windows desktop applications built with Delphi & C++Builder shine.

In this new version v10.5 we bring several new UI features:

Emoji support in HTML engine

For some time now, support for the use of emoticons is built-in standard in the Windows operating system. In the Windows operating system this is handled via a multi-color Truetype font Segoe UI Emoji. Regular Windows GDI API based controls (which most standard VCL controls are) cannot use multi-color Truetype fonts. To take advantage of this, for native applications, at minimum the Direct2D API needs to be used. We did the work for you, our HTML engine was updated with the capability to render multi-color Truetype fonts and with this the ability to render emoticons specified via HTML. The HTML standard prescribes a whole range of values for the various emoticons that exist. You can check the list here. In a nutshell, if you write in HTML
<p style="font-size:100px">&#128540;</p>
<p>I will display &#128540;</p>
it will render as:

😜

I will display 😜

So, now you can add Emoji decimal values in your HTML used for our VCL components that can render it. This includes labels, listbox, combobox, grid, navigation controls, panels and so much more.



New TAdvEmoticonPickerDropDown

Offering an easy to use UI with which you can select such emoticon. The TAdvEmoticonPickerDropDown can directly return the HTML code for the selected emoticon via AdvEmoticonPickerDropDown.EmoticonHTML: string property.

This new TAdvEmoticonPickerDropDown is used in the design-time HTML string property editor for controls that are enabled with HTML rendering.

New web-style form input control validation

In web forms, we are used to validation with clear indication on input controls where a value was not entered or was entered incorrect. In VCL Windows desktop applications, this is less common but it can add value to the user experience. While it is possible to do this all manually with showing extra labels with info on why an input entry is incorrect, we have created an easy to use concept for displaying validation feedback to users. This consists on one side of a centralized component (or multiple components) that hold the settings for the validation tooltip and in the TMS input controls like TAdvEdit, TAdvComboBox, TAdvSpinEdit, TAdvDateTimePicker, ... and all their descendent classes there is the method control.ShowValidation() / control.HideValidation() added to easily show and hide a certain validation text. For standard VCL controls or other 3rd party controls, the generic method ShowValidator(Control, Text, ValidatorSettings) or HideValidator(Control) are provided. Combining this, you can easily create validation screens like in this example:



Input control balloon hints

Another helper for guiding users to make correct form entries, is via a balloon hint. We have also extended our input controls like TAdvEdit, TAdvComboBox, TAdvSpinEdit, TAdvEditBtn, ... and their descendent classes with ShowBalloon() / HideBalloon() methods. With these methods you can give clues to users when he is not entering correct values as the user leaves the control or while typing. It offers 4 types : neutral, information, error or warning types.



Get started

TMS VCL UI Pack v10.5 is a free update for all active TMS VCL UI Pack, TMS Component Studio, TMS VCL Subscription and TMS ALL-ACCESS users. Either download the update from your "My Products" page after login or if you purchased a bundle, use TMS Subscription Manager that handles the download & update for you.
If you have not used TMS VCL UI Pack yet, there is a fully functional trial version of this new release. It brings you all these enhancements on top of the already extensive set of components including : grid, planner, ribbon, syntax memo, treeview, navigation control, enhanced editors, panels, ... and much much more.

TMS WEB Core v1.6 tips & tricks

$
0
0



We are pleased to share two more tips for using TMS WEB Core v1.6 Pesaro. The first tip is for how you could implement on the fly filtering on a TWebResponsiveGrid. The second tips concerns the dynamic creation and use of a TFrame.
Let's dive into the first tip right-away with showing filtering for the TWebResponsiveGrid.

Filtering in a responsive grid

TWebResponsiveGrid is a grid UI control that is responsive. This means that the number of columns will depend on the available window width in the browser. In this sample, we configured the TWebResponsiveGrid that about 200 pixels width is needed for a grid item and that the number of columns as such, will depend on how many items of width 200px fit in the browser window width. Each item of the TWebResponsiveGrid consists of a small snippet of HTML filled with data from a JSON HTTP GET request response. This JSON contains an array of JSON objects with information about cars. One such item is for example:

{
    "Brand": "BMW",
    "Model": "Z8",
    "Hp": 400,
    "Max speed": 250,
    "City": "Munchen",
    "Country": "Germany",
    "Type": "cabrio",
    "Picture": "bmw1.jpg",
    "Year": 2000,
    "Price": 95000,
    "Cylinders": 8
}
The HTML template for the item is set to:

'<b>(%Brand%) (%Model%)</b><br><i>(%Country%)</i>
<br><img src="https://download.tmssoftware.com/tmsweb/demos/tmsweb_responsivegrid/img/(%Picture%)">
<br>Year:<b>(%Year%)</b><br>Price:<b>(%Price%)€</b>';


As you can see, it will fetch Brand, Model, Country, Year, Picture and Price from the JSON.

When the JSON is loaded, all car items become visible in the responsive grid.

Now comes the code to filter which car items will be visible. We will let the filter apply in this case on the car brand and car model. That means that when a value typed in the filter matches either brand or model, the item will be displayed. The code to perform this filtering becomes:

var
  i: integer;
  f,s,a: string;
begin
  if edFilter.Text = '' then
  begin
    for I := 0 to carlist.Items.Count - 1 do
      carlist.Items[i].Visible := true;
  end
  else
  begin
    f := Uppercase(edFilter.Text);

    for i := 0 to carlist.Items.Count - 1 do
    begin
      s := carlist.Items[i].JSONElementValue['Brand'];
      a := carlist.Items[i].JSONElementValue['Model'];

      s := Uppercase(s);
      a := Uppercase(a);

      carlist.Items[i].Visible := (pos(f, s) > 0) or (pos(f, a) > 0);
    end;
  end;
end;
As you can see, we extract the car brand and model via the JSON object attached to the item and when there is a match, the item is visible otherwise not. When the filter changes, we first set all items as visible again, ensuring that any previous filtering operation is undone.
That's it. There is nothing more to it. The display work is all handled automatically by the TWebResponsiveGrid.



Dynamically creating, using and destroying a frame

In TMS WEB Core, you can use a TFrame just like you can in a Delphi VCL Windows application. You add your UI controls + UI control logic to the frame and you can use this frame on other forms in the VCL application. In TMS WEB Core, the concept is exactly the same. Here we created a frame with a common UI pattern: two listbox where items can be moved from left listbox to right listbox and vice versa. This UI and its code is added to a frame.

Now, to use this frame, we just need to add the unit of the frame to the uses list and the following code will from a single button click dynamically create the frame and destroy it:

procedure TForm1.btnFrameClick(Sender: TObject);
begin
  if Assigned(ListFrame) then
  begin
    ListFrame.Free;
    ListFrame := nil;
    btnFrame.Caption := 'Show frame';
  end
  else
  begin
    ListFrame := TListFrame.Create(Self);
    ListFrame.LoadFromForm;
    ListFrame.Parent := Self;
    ListFrame.LeftList.Items.Add('BMW');
    ListFrame.LeftList.Items.Add('Mercedes');
    ListFrame.LeftList.Items.Add('Porsche');
    ListFrame.LeftList.Items.Add('Audi');
    btnFrame.Caption := 'Hide frame';
  end;
end;
The only difference here with the VCL is that we need to call ListFrame.LoadFromForm. The reason for this is that in a TMS WEB Core application, there is no streaming happening from a DFM file. That would be an extra resource to be loaded & parsed and would not be a good idea from a performance perspective. So, the equivalent of loading the DFM is performed by calling ListFrame.LoadFromForm which actually initializes the frame fully in code.



As you can see, TMS WEB Core not only makes it extremely easy to do things like this in a web client application, but offers most of the concepts Delphi developers are used to from developing RAD component based Windows VCL applications to do away with as much as possible of the learning curve.

You can download the full source code of the two sample projects here to use with TMS WEB Core v1.6 Pesaro.

 

Note that these exact same projects will also be usable when we release very shortly the update of TMS WEB Core for Visual Studio Code with these latest framework & compiler updates!



TMS FNC Cloud Pack v1.3 released!

$
0
0

Intro

2021 is just started and with only a few weeks into the new year we are proud to present you the TMS FNC Cloud Pack 1.3 update which brings a new set of services, big improvements to existing services as well as a new design time authentication dialog and last but not least: service wrappers.



Below is an overview of what you can expect when installing the TMS FNC Cloud Pack 1.3 update.

New services

When installing the update you get access to the following new services:

  • Box: cloud storage service
  • Google Analytics: analyze web site statistics
  • SumUp: payment service
  • Sentry: cloud logging service
  • Exceptionless: cloud logging service
  • Rollbar: cloud logging service
  • Cloudinary: file upload service

Service wrappers

The update also brings 3 new service wrapper components:

  • TTMSFNCCloudLogger: wrapper around cloud logging services: Sentry, Exceptionless and Rollbar
  • TTMSFNCCloudStorageServices: wrapper around all cloud storage services
  • TTMSFNCCloudTranslation: wrapper around translation services: Microsoft Translator, Google Translate and IBM Watson Translator

Improvements

Improvements are made in various areas:

  • Response headers accessible in TTMSFNCCloudBaseRequestResult
  • Download attachments in Microsoft Outlook Mail & Google GMail
  • Dropbox upgraded to version v2
  • Google Drive upgraded to version v3
  • MoveFile and MoveFileToRoot for all cloud storage services

Designtime helper

After installing update 1.3 you'll notice the Authentication property has an option to popup an authentication helper dialog. This dialog will allow you to fill in your client-id, secret and/or API key (depending on the service), authenticate and save the result on your machine. This depends on the PersistTokens settings. When opening the form again, the settings can be restored by opening the authentication dialog again and clicking authenticate button. Additionally, when you are unsure on how to obtain a client-id, secret or API key, there are 2 buttons that will help you with that. The "Help" button will take you to this page, which is a general overview for all supported services and step-by-step instructions on how to register your application and obtain the necessary information for authentication, and a "Create Client ID/API Key" button that will immediately take you to the page where you can (after successful login) generate a Client ID and/or API key.



Demos

This update also brings 3 new demos, demonstrating the wrapper capabilities for the storage, logger and translation services. Stay tuned for the next release which will add more demos and add more services as well as improve existing ones.


Webinar: Develop Web Clients from the Delphi IDE

$
0
0



We look forward to connect with you at the upcoming webinar! Learn about the new features in the latest release v1.6 Pesaro in the upcoming webinar organized by Barnsten.

Webinar: Develop Web Clients from the Delphi IDE
TMS WEB Core is based on compiling Delphi UI code to JavaScript and creating this way what that Delphi developers are used to. A TMS WEB Core application can contain multiple forms. These multiple forms will be hosted in a JavaScript application a web browser user can navigate to via a single page URL. Any modern HTML5 compliant browser can run TMS WEB Core web client applications. This includes Chrome, Safari, Edge, Firefox, Firefox Developer Edition, Opera.

Our CTO Bruno Fierens will take a tour around TMS WEB Core and the exciting new capabilities v1.6 brings and how to use this in a productive way to develop web client applications. Register now for the webinar to ensure your seat.

This will be an interactive webinar. You can ask your questions during or after the webinar.
Is a FREE online event, organized by Barnsten Netherlands, on Janaury 26th, 2021.

Learn more



Visit barnsten.com, register and participate.

Freebie Friday: capture controls or forms

$
0
0



New year, new ideas. So, I'm happy to kick off with one of the many new ideas we have, which is the Freebie Friday!

Freebie Friday is simple. We share a useful code snippet that might be handy in your projects. We present it, you copy and paste it and you use it in your applications where you see use for it. Freebie Friday free source code snippets are the result of our daily work, writing components, offering support & consulting for customers ... Over time, a huge collection of useful code builds up and instead of letting this collect dust, we cheer up your Friday, just before the weekend and present it here.

This first freebie is two routines that enable you to capture a control as image. The first that might come up is, why write a routine for this, a control offers control.PaintTo() and we can just use that to have the control paint to a canvas and save that to a file.

In theory yes, in practice, sadly this doesn't work well with many controls. So, therefore these two routines that do work with any VCL control and as a bonus, it works with a VCL form as well, so you can capture entire forms to a bitmap or image.

Here we go, here is the code:

interface

uses
  Classes, Windows, Messages, Graphics, JPEG, Controls, Types, Forms;

procedure CaptureControl(AControl: TControl; ABitmap: TBitmap);
procedure CaptureControlToJpeg(AControl: TControl; AFileName: string; AQuality: integer = 70);

implementation

uses
  Winapi.DwmApi, SysUtils;

procedure CaptureControl(AControl: TControl; ABitmap: TBitmap);
var
  LDesktopDC: HDC;
  LRect: TRect;
  LDWMRect: TRect;
  LPt: TPoint;
begin
  LPt := AControl.ClientToScreen(Point(0,0));

  LRect := Rect(LPt.X, LPt.Y, LPt.X + AControl.Width, LPt.Y + AControl.Height);

  if (AControl is TWinControl) and (AControl as TWinControl).HandleAllocated then
  begin
    GetWindowRect((AControl as TWinControl).Handle, LRect);
  end;

  if (AControl is TCustomForm) and (AControl as TCustomForm).HandleAllocated then
  begin
    GetWindowRect((AControl as TCustomForm).Handle, LRect);

    if (Win32MajorVersion >= 6) and DwmCompositionEnabled then
    begin
      if (DwmGetWindowAttribute((AControl as TCustomForm).Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @LDWMRect, SizeOf(LDWMRect)) = S_OK) then
      begin
        LRect := LDWMRect;
      end;
    end;
  end;

  LDesktopDC := GetWindowDC(GetDesktopWindow);
  try
    ABitmap.PixelFormat := pf24bit;
    ABitmap.Height := LRect.Bottom - LRect.Top;
    ABitmap.Width := LRect.Right - LRect.Left;

    BitBlt(ABitmap.Canvas.Handle, 0, 0, ABitmap.Width, ABitmap.Height, LDesktopDC, LRect.Left, LRect.Top, SRCCOPY);
  finally
    ReleaseDC(GetDesktopWindow, LDesktopDC);
  end;
end;

procedure CaptureControlToJpeg(AControl: TControl; AFileName: string; AQuality: integer = 70);
var
  LJpeg: TJpegImage;
  LBmp: TBitmap;
begin
  LBmp := TBitmap.Create;
  try
    CaptureControl(AControl, LBmp);
    LJpeg := TJpegImage.Create;
    try
      LJpeg.Assign(LBmp);
      LJpeg.CompressionQuality := AQuality;
      LJpeg.SaveToFile(AFileName);
    finally
      LJpeg.Free;
    end;
  finally
    LBmp.Free;
  end;
end;
To use these routines, you can do this with:
begin
  // capture a control to JPEG file setting JPEG quality to 90
  CaptureControlToJpeg(mycontrol, 'mycontrol.jpg', 90);
  // capture a form (Self) to JPEG file setting JPEG quality to 50
  CaptureControlToJpeg(Self, 'myform.jpg', 50);
end;
To capture a control to bitmap, use:
var
  LBmp: TBitmap;
begin
  LBmp := TBitmap.Create;
  try
      CaptureControl(mycontrol, LBmp); 
      // do what you want with the bitmap here 
  finally
    LBmp.Free;
  end;
end;

Enjoy and have a good weekend!

VCL Grid goodies

$
0
0



Our VCL component TAdvStringGrid is one of our components with the longest history. It served thousand and thousands of software developers on planet Earth and we are incredibly thankful for an not oversee-able amount of ideas from users that went into the grid during all these years.
There is so much power packed into TAdvStringGrid that it becomes a challenge to know and unlock all its power. Hence this new series "Grid Goodies". And that is not all, our colleague & chief evangelist Holger Flick has some more things up in his sleeves to help you getting the most out of our VCL grids. But I don't want to reveal more about this upcoming surprise at this time. Let's bring two extremely easy to use yet powerful features of TAdvStringGrid.

Smart clipboard

The grid has numerous settings to fine-tune the exact behavior for clipboard handling you want to have. One lesser known feature is the built-in smart clipboard handling. This is enabled by setting grid.Navigation.AllowSmartClipboard = true. What this means is that when you copy a range of cells values to the clipboard with grid.CopySelectionToClipboard and you paste this range into a cell range with a different size, it will try to perform in a smart way what you expect on the different range of cells where you paste, like for example automatic number or date increments. This isn't limited to performing copy & paste, it can also be enabled for when you select a range of cells and resize it with the mouse. This is enabled with grid.SelectionResizer = true. Of course, for this to work, the grid must be enabled for editing and cell range selection. We decided to make it ultra easy to enable all this functionality by setting one public property instead of going over all different properties involved here, and that is:
grid.SpreadSheet := true;
When this is enabled, this becomes possible without any code except the button OnClick handlers calling grid.CopySelectionToClipboard / grid.PasteSelectionFromClipboard:



Easy highlighting

The second goodie we want to reveal is highlighting matching text in the grid. Although the grid has built-in filtering, various built-in search functionality, on the fly highlighting of matching values can be that convenient feature you are looking for. And it cannot be easier to use. All you need to do is call:
grid.Hilight(FixedCells, CaseSensitive, YourText);
So, for this example, all we did was attach an OnChange event handler for the edit control and call from there:
procedure TForm1.Edit1Change(Sender: TObject);
begin
  AdvStringGrid1.HilightInGrid(false,false,Edit1.Text);
end;


Oh, one small extra setting was done! We changed the highlight color from the standard blue to yellow background and red text with:
  AdvStringGrid1.HighlightColor := clYellow;
  AdvStringGrid1.HighlightTextColor := clRed;
Let us know what your favorite grid feature is or what other interesting little goodie you discovered recently and we will be happy to share it here in a follow up #GRIDGOODIES.

TMS WEB Core for Visual Studio Code v1.2 released!

$
0
0



After we released TMS WEB Core v1.6 Pesaro for Delphi & Lazarus on earlier in January this year, we are pleased to inform that the release of TMS WEB Core for Visual Studio Code is now here as well. This brings the framework and language support on par with the versions for Delphi or Lazarus.

Focus on new language features


Among the major new capabilities of the pas2js compiler are:

  • Generics
  • Attributes
  • Class constructors
  • Resource strings
  • Async procedure decorator
  • Await support
  • JavaScript promises support
  • Resource file support

So, the long awaited support for generics (that comes with the accompanying RTL unit generics.collection) and attribute support will allow that nearly all of your existing Delphi code can move over to TMS WEB Core for creating web applications.

On the other side, the new support for async procedures, for promises and for await, will mean that you can use modern web paradigms for handling asynchronous functions easier. These features async, promise and await are direct equivalents to the existing JavaScript functionality and do not exist for native Delphi application development.

Updating is easy


Updating to the new TMS WEB Core for Visual Studio Code v1.2 is easy. Either you obtained TMS WEB Core for Visual Studio Code from the Microsoft marketplace and the IDE will handle the update automatically for you or you can download the latest version from our website. Either way, you will need to reactivate either your trial or full registered version credentials.

What's next?


We have been working a long time on v1.2 but in parallel we have already made significant advances for the next release v1.3. The new version will bring component package support. So, from the IDE, you will be able to install additional component packages including creating your own custom component packages. When this is in place, your array of available components at design-time will rise significantly as our full range of TMS FNC Components will become readily available from TMS WEB Core for Visual Studio Code as well. For now, this use was limited to using the classes via runtime code.

Get started now


If you didn't get your feet wet already with RAD component based Object Pascal based web client development, now is the time to enter this fast moving & fascinating world. The sheer amount of new possibilities and territories is staggering. You cannot only develop no-deployment cross platform rich web client applications, but also offline usable and installable PWA's for use on mobile devices bypassing Apple or Google stores. Or you can use the Electron framework to create cross-platform desktop applications for Windows, macOS and Linux with a modern and fresh looking HTML/Web based GUI. And with Visual Studio Code, you can do all this directly from your favorite operating system: Windows, macOS or Linux.

Learn here about the new generics support:



Get the TMS WEB Core for Visual Studio Code v1.2 trial or use TMS WEB Core for Visual Studio Code v1.2 as part of the TMS ALL-ACCESS subscription, the no-nonsense subscription to our entire product portfolio coupled with priority technical support services.

Async keyword in TMS WEB Core (Leon Kassebaum)

$
0
0


Async? What's that?
Maybe you have already heard about the two concepts of synchronous and asynchronous processing of code statements. I give you an example. Let's have a look at a "normal" Delphi application and the following lines of code:
procedure MyProc();
var
  lResponse : string;
begin
  lResponse := ExecuteServerRequest;
  lResponse := 'Response: ' + lResponse;
  Writeln(lResponse);
end;
I think you know this type of application (maybe a VCL or FMX app) and of course line 6 is executed after receiving the servers response. This behavior is called synchronous because the computer performs the written code line by line.

If you write the same type of code in JavaScript things are working differently. Let me explain why. First of all pure JavaScript is single-threaded. Due to that fact it only has the possibility to perform your code line by line, so to say JS code is executed synchronously. But this only applies to JS and not for browser api calls. Imagine, if you perform an http request as I did in the example above, you call functions from the browser api. At this point the JS engine can continue with the next statement (next line of code) and the browser performs his task in the background. As soon as he is ready he gives you a callback. This is due to the fact that a website always has to react e.g. for resizing. If this would not be possible you would see an hourglass when connecting to a webserver (which lasts a bit) and your whole web app would be frozen. I think you know the well known Blue circle of death from windows.

The reason in JS style
So what to do if you want to connect to a webserver? The thing is that you have to wait for the response until you can continue your code. In JS the answer is splitted to three statements: async, await and promises. The concept behind this is that the promise which executes your code (e.g. pulling a webserver), has two callback functions. One is called if everything was successful and the other handles possible errors. Maybe it is better to give you a tiny example in JS:
...
let lPromise = new Promise(
  function(ASuccess, AFailed){
    setTimeout (
      function(){
        ASuccess("Waited 2 seconds") ;
      }, 2000);
    });
...

I created a promises which performs setTimeout() to wait for 2 seconds and then he calls the success function. The next step is that you can mark a function as async so that it returns a promise and no longer maybe a string. This
...
async function MyAsyncFunction(){
  return "Hello World!" ;
}
...

is the same as
...
async function MyAsyncFunction(){
  return new Promise(
    function(ASuccess, AFailed){
	  ASuccess("Hello World!");
	});
}
...

I know this is hard to understand but please keep in mind that this is just another way to return a promise but it is much more legible.

Calling this function with the await keyword makes sure that your code waits for the success callback function of the returned promise and calculates the result of this function which can be the response of the server. Think of the lPromise from above which simply waits 2 seconds. If I would run the following lines of code

console.log("Before calling");

  let lPromise = new ...

console.log(await lPromise);

it would first print Before calling to the console and wait 2 seconds in order to print Waited 2 seconds.

Available in TMS WEB Core?
Sure, this is a great feature of JS and should be possible in TMS WEB Core to build modern web apps. But it is not. So sorry, end of article.

No, just fun! Of course you can use it! The compiler magicians from the FPC community integrated this for you.

How to use
The use of async and await are very similar to its usage in JS. I will start with the async identifier. To convert a normal function to an async function you can do this:

function TMyObject.ThisMethodIsAsync: Integer; async;
begin
  ...
end;

or this, which is more readable and compilable by the Delphi compiler because he does not know the async keyword:
TMyObject = class(TObject)
  [async]
  function ThisMethodIsAsync: Integer;
end;

...

function TMyObject.ThisMethodIsAsync: Integer;
begin
  ...
end;

The mindblowing effect on this async keyword is that ThisMethodIsAsync no longer returns an Integer but now a TJSPromise! Remember, this is very similar to JS. It is also possible to create this promise manually. This way you can call the success callback function for returning your result. Technically this is the same but your code looks much more than Delphi code if you use async. Look at this:
function TMyObject.ThisMethodIsAsync: TJSPromise;
begin
  Result := TJSPromise.new(
    procedure(ASuccess, AFailed: TJSPromiseResolver)
    begin
      ASuccess(7);
    end);
end;

This example just returns the value (7). One problem could be that now you cannot share this source code between Delphi (maybe VCL) and TMS WEB apps because there is no TJSPromise in the VCL. Well, now there is a tiny base for async calls because the promise has a success callback function. But how to get the Result of async functions? Good question but as I said, this is very similar to JS, so we can use await. Here's the syntax:
procedure TMyObject.CallAsyncFunction;
var
  lBuffer: Integer;
begin
  lBuffer := await(ThisMethodIsAsync);
  ...
end;

In the lines below calling that async function, you can be sure that the result is stored in lBuffer and there won't be any callback function which returns later. If you want to have a look at more examples please visit the Pas2JS homepage.

Compiler magic
If you want to write and compile your code in the Delphi IDE you should pay attention that the dcc compiles your code (otherwise all of your code is marked red). Because of that the whole WEBLib exists twice. One implementation is the real one which is executed in the browser (Core Source) and the other one is for Delphi (Component Library Source). Of course you want to use programming assistance and to give Delphi a break you should give him valid Delphi code so that he can make suggestions. E.g. this is why I recommend you to use the async attribute. At this points the stub units in the "second" WEBLib are used because all functions from the real one are defined here as well but in valid Delphi syntax.

But anyway, let's have a concluding look at await. The thing is that Pas2JS recognizes async functions as functions which return a promise, but Delphi thinks that it returns e.g. a string or an Integer.
Well, the TMS team dealt with making await Delphi conform and defined it in the stub units like this:
function Await(const AValue: string): string; overload;
begin
  Result := AValue;
end;

As you can imagine this only works for a finite amount of types (in this case primitive types like string and Integer). So to say, if you create an async function which returns TMySpecialType the Delphi programming assistance crashes because await is not defined for it whether it compiles with Pas2JS. But the TMSWEBCompiler provides some compiler magic. It exists the following record in the unit JS.pas (since I mean the stub unit it is located in the Component Library Source folder, not in the Core Source folder):
TAwait = record
  public
    class function Exec<T>(const AValue: T): T; static;
    ...
end;
This allows you to write the following:
...
var
  lValue: TMySpecialType;
begin
  lValue := TAwait.Exec<TMySpecialType>(AsyncFunctionReturningThisType);
...

Internally this is only converted to
...
var
  lValue: TMySpecialType;
begin
  lValue := await(AsyncFunctionReturningThisType);
...

You should better use this generic method because this is compilable with Delphi and your programming assistance keeps working.

Conclusion
So to say, we have found a possibility to "synchronize" our code but keep in mind that it is still asynchronous! The huge advantage of this is that your code becomes very legible (you will thank yourself in the future) and you use the latest concepts of the JS engine, too!

Author: Leon Maximilian Kassebaum

Viewing all 1006 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>