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

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

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