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

Embarcadero Germany webinar about TMS WEB Core

$
0
0



With TMS WEB Core v1.5 Rimini just released, enthusiast German speaking Delphi web developers can learn about TMS WEB Core and in particular about the new features in the latest release v1.5 Rimini in the upcoming webinar organized by Embarcadero Germany.

Our chief evangelist Holger Flick will take a tour around TMS WEB Core and the exciting new capabilities v1.5 brings to increase your productivity for creating classic web applications, installable mobile applications (PWA or progressive web applications) and cross-platform Electron desktop applications. And this all from your familiar powerful Delphi 10.4 Sydney IDE. Bruno Fierens will also attend the webinar and will assist to handle all your questions. Register now for the webinar to ensure your seat.

Here is the original announcement text for the webinar in German:

TMS WEB Core ist für viele Delphi-Entwickler zu einem beliebten Entwicklungstool für Webanwendungen geworden. TMS Software hat in den letzten zwei Jahren regelmäßige Updates bereitgestellt, wodurch die Anzahl der Steuerelemente und Technologien zur Erstellung beeindruckender Webanwendungen ständig zunahm.

Dieses Webinar konzentriert sich auf die neue Version 1.5 Rimini, in der zwei Werkzeuge vorgestellt werden, die die visuelle Anwendungsentwicklung erheblich verbessern. Die Interaktion mit Webdesignern, die nicht an der Programmierung der Anwendung beteiligt sein müssen, wird viel einfacher werden. Außerdem werden neue Steuerelemente für handschriftliche Unterschriften, Styling, Benachrichtigungsfenster und Web Sharing eingeführt. Schließlich wird es mit der neuen Version möglich sein, datenbankgestützte Electron Desktop-Anwendungen zu erstellen, die direkt mit MySQL- und PostgreSQL-Datenbanken verbunden sind.

Jetz hier anmelden für das Webinar!


Generate QR codes with TMS WEB Core

$
0
0

TMS WEB Core already has a TWebQRDecoder component to decode QR codes. It's evident that we need something that works the other way around and creates QR codes instead. Meet our new addition to tackle this problem: TWebQRCode.

TWebQRCode is a wrapper around the qrcode.js JavaScript library. qrcode.js is a small library with the purpose of creating a QR code based on a string input.

Functionality

Not surprisingly, you can generate a QR code based on a text. Just drop the component onto the form, and set the TWebQRCode.Text property:
procedure TForm1.WebButton1Click(Sender: TObject);
begin
  WebQRCode1.Text := WebEdit1.Text;
end;


You can also retrieve the QR code as a base64 encoded string or as a TBitmap. To retrieve this data, use the GetBase64/GetBitmap methods or their GetBase64Async/GetBitmapAsync versions. The reason behind an async version of these methods is simple: GetBase64 and GetBitmap will work right away if the component is visible, because the underlying image source is a base64 encoded string. If you want to get a QR code data without showing any images, then the process will be asynchronous because the image needs to be created and loaded on the fly by the library. These asynchronous versions work with anonymous methods. This way you have full control over the retrieved data.
procedure TForm1.WebButton1Click(Sender: TObject);
var
  qr: TWebQRCode;
begin
  qr := TWebQRCode.Create(Self);
  qr.Width := 200;
  qr.Height := 200;
  qr.Text := 'my text';
  qr.GetBase64Async(procedure (AData: string)
  begin
    //do something with AData
  end);
end;
And last but not least, the QR code can be downloaded as an image. Only PNG format is supported by the library.
procedure TForm1.WebButton1Click(Sender: TObject);
begin
  WebQRCode1.Download('myqrcode.png');
end;

Example

As a small example, we are going to create a small business card generator application with TTMSFNCPDFLib. TTMSFNCPDFLib makes it possible to create PDF files on the fly and if we combine it with TWebQRCode then we have an application which can generate PDF files with QR codes directly in the client!


To keep it short, we are going to focus on the QR code drawing. As a first step, we need to load the default fonts and disable the button until the fonts are loaded.
procedure TForm1.WebFormCreate(Sender: TObject);
begin
  WebButton2.Enabled := False;
  Application.OnFontCacheReady := DoFontCacheReady;
  AddFontToCache('https://download.tmssoftware.com/tmsweb/pdf/fonts/arial.ttf');
  AddFontToCache('https://download.tmssoftware.com/tmsweb/pdf/fonts/tahoma.ttf');
end;

procedure TForm1.DoFontCacheReady(Sender: TObject);
begin
  WebButton2.Enabled := True;
end;
For the business cards we want to turn the website URL into a QR code. So the next step is to create a TTMSFNCPDFLib instance, get the TBitmap from TWebQRCode and draw it. We get the URL from a TWebEdit so if we change the website URL the underlying library needs to update the QR code first. In this case it's better to use the GetBitmapAsync method.
procedure TForm1.WebButton2Click(Sender: TObject);
var
  PDF: TTMSFNCPDFLib;
  I: Integer;
begin
  WebQRCode1.Text := edtWebsite.Text; //Set URL
  WebQRCode1.GetBitmapAsync(procedure (ABitmap: TBitmap) //Wait for bitmap to load
  begin
    PDF := TTMSFNCPDFLib.Create;
    try
      PDF.BeginDocument('sample.pdf');
      PDF.PageSize := psA4;
      PDF.Header := '';
      PDF.Footer := '';
      PDF.NewPage;
      PDF.Graphics.Font.Color := gcBlack;
      PDF.Graphics.Font.Style := [];
      //Draw with PDF here
      PDF.EndDocument(True);
    finally
      PDF.Free;
    end;
  end);
end;
We want to draw the business cards multiple times so it's better to create a method for it. We can then introduce a loop and call our drawing method with PDF and ABitmap as a parameter.
procedure TForm1.DrawBusinessCard(APDF: TTMSFNCPDFLib; ALeft, ATop, ARight, ABottom: Integer; AQR: TBitmap);
begin
  APDF.Graphics.DrawRectangle(RectF(ALeft, ATop, ARight, ABottom));
  //text drawing would come here
  APDF.Graphics.DrawImage(AQR, RectF(ARight - 95, ABottom - 90, ARight - 25, ABottom - 20));
end;
This sample not only shows how easy it is to create PDFs with QR codes but also demonstrates the power of TMS FNC and TMS WEB Core combined! You can play around with the full demo here.
But wait, we have some more good news: we made this component available through our TMS WEB Core Partner program which means that you can download it from here for free!

To install, open, compile & install the package from the "Component Library Source" folder. This will install the design-time TWebQRCode component.
For use at runtime, make sure that the "Core Source" folder is in your TMS WEB Core specific library path that you can set via IDE Tools, Options, TMS Web, Library path.

Free component to handle ZIP files in a TMS WEB Core application

$
0
0



Yesterday we introduced TWebQRCode as a free component to be used with TMS WEB Core. If you would like to work with ZIP files in a web application then we have good news for you! We created another free component: TWebZip.

TWebZip is a wrapper around the open source JSZip library. JSZip makes it possible to create, read, modify and download ZIP files directly in a client application. For limitations of the library please check the Limitations page.

Features of TWebZip

The supported data types are: string, base64 encoded string (via a parameter setting), TJSArrayBuffer and TBytes.

Drop the non-visual TWebZip component onto the form and you have an empty ZIP file already! You can also open a ZIP file, for example through a TWebFilePicker:
procedure TForm1.WebFilePicker1Change(Sender: TObject);
begin
  if WebFilePicker1.Files.Count > 0 then
    WebFilePicker1.Files[0].GetAsArrayBuffer;
end;

procedure TForm1.WebFilePicker1GetFileAsArrayBuffer(Sender: TObject; AFileIndex: Integer; ABuffer: TJSArrayBufferRecord);
begin
  WebZip1.Open(ABuffer);
end;

procedure TForm1.WebZip1ZipLoaded(Sender: TObject);
begin
  //This is the implementation of the OnZipLoaded event:
  //here we know that the ZIP was successfully opened
  //and we can proceed with related calculations/tasks
end;
To add files to the ZIP, use the Add method. The first parameter is the filename with extension and the second parameter is the data to be added to the file. Keep in mind that if your ZIP already contains a file with a given name then it will override the content.
WebZip1.Add('subfolder/sub.txt', 'I''m in a subfolder!'); //Add sub.txt in the 'subfolder' folder
WebZip1.Add('hello.txt', 'Hello World'); //Adds hello.txt to the ZIP and sets the content to 'Hello World'
WebZip1.Add('hello.txt', 'Hello ZIP'); //Overrides the content of hello.txt
To read the content of a file, use the ReadAsString, ReadAsArrayBuffer or ReadAsBytes method based on which data type you need for further processing. These methods are asynchronous. The first parameter is the filename you want to read and the second is the anonymous method for processing the data.
WebZip1.ReadAsString('hello.txt', procedure(AFileName, AData: string)
begin
  //process AData here
end);
To remove files, use the Remove(FileName) or RemoveAll methods.
WebZip1.Remove('hello.txt'); //removes hello.txt from ZIP
WebZip1.RemoveAll; //removes all of the files from the ZIP
Download the ZIP you created or modified with different compression levels. More information on these levels can be found here.
WebZip1.Download('myzip.zip', zcStore); //no compression
WebZip1.Download('myzip.zip', zcDeflateLevel1); //best speed
WebZip1.Download('myzip.zip', zcDeflateLevel9); //best compression
Follow your download progress by implementing the OnProgress event:
procedure TForm1.WebZip1Progress(Sender: TObject; APercent: Single; ACurrentFile: string);
begin
  WebProgressBar1.Position := Round(APercent);
end;
There are also extra properties for: file count (TWebZip.FileCount), file names (TWebZip.FileName, TWebZip.FileNames) and file comments (TWebZip.FileComment).

If you would like to see how TWebZip works in practice, then head over to our demo where you can upload images (JPEG or ZIP containing JPEGs) and download their grayscale version in a ZIP file. As we mentioned at the beginning of this article, TWebZip is available for free through our TMS WEB Core Partner program and you can download it from here.

To install, open, compile & install the package from the "Component Library Source" folder. This will install the design-time TWebZip component.
For use at runtime, make sure that the "Core Source" folder is in your TMS WEB Core specific library path that you can set via IDE Tools, Options, TMS Web, Library path.

TMS WEB Core for Visual Studio Code public beta is here!

$
0
0



After a long, intense and exciting development cycle, we have the first public beta of TMS WEB Core for Visual Studio Code ready for you.
Now you can discover how you can productively create web client applications with the TMS WEB Core framework from the Visual Studio Code IDE.

What we did?


Originally, a quite complex add-in was written for the Delphi IDE to host development of web client applications based on the TMS WEB Core framework and using the pas2js compiler technology. The second step was to provide a similar IDE integration for the Lazarus IDE.
Now a plugin was created for the Visual Studio Code IDE that offers everything expected from a modern IDE: form designer, tool palette, object inspector, structure pane, code-editor with code completion, ... So, directly from Visual Studio Code you can create web client application projects based on the TMS WEB Core framework and debug, compile and run these from the IDE. No additional tools are needed to create fully working web client applications.

Why we did it?


To understand why we endeavored to bring TMS WEB Core for Visual Studio Code, it is import to understand what Visual Studio Code is. Visual Studio Code is a popular extensible code editor from Microsoft based on Electron technology. This means an application based on web technology that can be hosted via the Electron framework into a desktop application that is cross-platform. It is the 'based on web technology' that makes it so interesting. This means that the whole experience to develop and design a web application is hosted in a web technology based IDE. So, you can design web components directly in a web environment resulting in a WYSIWYG experience. Using this technology brings a couple of nice features:

  • WYSIWYG form designer that also renders your HTML templates directly in the design
  • Debugging directly from the IDE, step through your Object Pascal code from the IDE
  • IDE runs on Windows, macOS and Linux
  • The IDE is out of the box high-DPI enabled
  • The Visual Studio Code ecosystem has many interesting additional plugins to enhance your development productivity



Who did it?


José Leon Serna, former Embarcadero chief IDE architect, had the idea and the expertise to host a full IDE experience within Visual Studio Code. It was like the most natural fit to form a team with TMS software having produced the TMS WEB Core framework and bring the IDE experience and framework together in Visual Studio Code. Almost 2 years of intense and often hard and complex development went into this project. One of the big challenges and major differences with how TMS WEB Core works in the Delphi IDE, is that in Visual Studio Code, the component framework is fully live while in the Delphi IDE, it is simulated using VCL. This challenged the framework quite a bit but the advantage is that all the hard work pays off for the robustness of the framework components overall.

For who did we do it?


Obviously, we developed TMS WEB Core for software developers who love a RAD component based development approach using a strongly typed and object oriented language that Object Pascal offers. We hope it attracts not only existing Object Pascal developers but also web developers who love the approach of a more object oriented and consistent component based architecture bringing productivity and business development oriented programming style. We hope it helps to strengthen the position of Object Pascal and ultimately also brings new developers to Delphi, for example to create Object Pascal based backend services based on technology such as Embarcadero RAD server or TMS XData.

What do we plan?


We hope to get your feedback during this public beta phase to get your feedback and comments that should allow us not only to make the first release as robust as possible but also to hear your thoughts to steer future development steps. We aim for a v1.0 release in Q3. After v1.0, focus will be on bringing features like PWA support, Electron support, 3rd party component install support and stay current with planned new exciting developments of the pas2js compiler.

What do I choose?


We realize there are perfectly valid reasons to choose any of the 3 IDEs that TMS WEB Core supports now. You can take advantage of the familiar Delphi IDE and simultanously develop web clients and backends from a single IDE. You might have a preference for development directly on macOS and opt for Visual Studio Code to develop the web client and use Delphi for the backend development. Or your daily operating system might be Linux and you prefer using the Lazarus IDE. As you can see, there is plenty of choice and options. We strongly believe in the freedom of choice and use whatever fits your needs and habits best. We took care to have project exchange-ability between Delphi TMS WEB Core projects and Visual Studio Code TMS WEB Core projects. We provide a converter to convert Delphi TMS WEB Core projects to Lazarus TMS WEB Core projects.

In a nutshell, these are very exciting times for Object Pascal developers. The importance is to have fun and being productive while developing, to focus on your business logic instead of the technology complexities. Go ahead and try our new public beta of TMS WEB Core for Visual Studio Code. We're eager to learn about your experiences and interested to hear where there might still be a couple of rough edges we need to polish.

One thing is sure, your #staycation won't be boring!

Create calendar events with TMS WEB Core

$
0
0



The world is busier than ever and unless you are gifted with an incredible memory you need your own agenda to keep track of all the appointments and events. Luckily there are media types that allow you to store and share calendaring and scheduling information: vCalendar and iCalendar. But what is the difference between the two? To put it simply, vCalendar is an older format while iCalendar a newer format that is based on vCalendar. Both formats are widely supported.

vCalendar and TMS WEB Core

In many cases if you download a VCS/ICS file your device will either automatically try to add it to your calendar or you first need to open the file and then it will prompt you to add it to your calendar - as long as you have an application installed that supports VCS/ICS.
So we asked ourselves: Can we create and download a VCS/ICS file directly from a TMS WEB Core client application? A few hours of research work resulted in a new non-visual component: TWebvCalendar.

TWebvCalendar is a component that implements the RFC2445 specification. It encapsulates the functionality of vCalendar and iCalendar in a Delphi-friendly way.

To change between the two formats, use the TWebvCalendar.vCalendarVersion property, where the vv1 value indicates vCalendar and vv2 refers to iCalendar. The default version is set to vv2 as most modern calendaring/scheduling applications support it anyway.
You can add the events either at design-time or programmatically via the TWebvCalendar.vEvents property, which is a collection of TvEvent items.
procedure TForm1.WebButton1Click(Sender: TObject);
var
  vevent: TvEvent;
begin
  vevent := WebvCalendar1.vEvents.Add;
  vevent.DTStart := EncodeDate(2020,8,1)+EncodeTime(10,0,0,0);
  vevent.DTEnd := EncodeDate(2020,8,1)+EncodeTime(12,0,0,0);
  vevent.Summary := 'My first appointment';
  vevent.Location := 'My location';
  WebvCalendar1.SaveToFile('mycalendar.ics'); //default is vv2
end;
The various TvEvent properties are all based on the specification linked above.

Example

We have some events coming up in the following weeks starting this Thursday (13th August) with a Webinar hosted by Embarcadero Germany. If you haven't already, you can still register here!
To keep track of all these events, we decided to create a Progressive Web Application (PWA). A PWA behaves just like a regular website when you visit it from your browser:



But as you can already see in the image, it's also possible to install it as an application on your device! After that, it can be accessed from the home screen:


From left to right the images are as follows: Application on the home screen, running the installed application and clicking the "Add" button.

The code itself is rather simple. First we need to make an HTTP request and process the incoming JSON response that contains all the events. It's important to mention that we store and retrieve the time for each event in UTC with no offset. This way when we convert a time to a JavaScript Date object and after that to a TDateTime object, the correct time zone is automatically handled. If you are currently not in the CEST time zone, then you are going to see a different time than what's seen in the picture above.

The next thing to do is to show the event items in a TWebResponsiveGrid. While we process the incoming data we can use the TWebResponsiveGridItem.ItemObject property to save everything we want to access later. Then to add these event to our calendar, we add a button to each of these grid items by implementing the TWebResponsiveGrid.OnItemCreated event:
procedure TForm3.WebResponsiveGrid1ItemCreated(Sender: TObject; Index: Integer);
var
  cont: TControl;
  btn: TWebButton;
  itm: TWebResponsiveGridItem;
begin
  itm := WebResponsiveGrid1.Items[Index]; //get the grid item

  cont := TControl.Create(WebResponsiveGrid1); //create a dummy TControl
  cont.Container := itm.ElementHandle; //assign the TJSHTMLElement of the item to the dummy control
  
  btn := TWebButton.Create(cont);
  btn.Parent := cont;
  btn.Caption := 'event Add';
  btn.Tag := Index; //set the Tag to the Index value
  btn.Cursor := crHandPoint;
  btn.ElementClassName := 'add-button'; //this CSS class contains the button positions
  btn.ElementPosition := epIgnore;
  btn.OnClick := DoEventClick;
  //Add the ElementHandle of the button to the ElementHandle of the grid item.
  //It depends on your specific item structure, but usually it looks something like:
  //itm.ElementHandle.appendChild(btn.ElementHandle);
end;
The DoEventClick method gets assigned to all of the buttons, so we are going to use the Tag property to differentiate between the different buttons. All that left to do is to create a TWebvCalendar instance and save the event to our device:
procedure TForm3.DoEventClick(Sender: TObject);
var
  ev: TEventItem; //this is a custom TObject class
  vcal: TWebvCalendar;
  vevent: TvEvent;
begin
  ev := TEventItem(WebResponsiveGrid1.Items[(Sender as TWebButton).Tag].ItemObject); //get the ItemObject 
  vcal := TWebvCalendar.Create(self);
  vcal.vCalendarVersion := vv2; //use iCalendar
  vevent := vcal.vEvents.Add;
  vevent.DTStart := ev.StartTime; 
  vevent.DTEnd := ev.EndTime;
  vevent.Summary := ev.Subject;
  if ev.Location <> '' then 
    vevent.Location := ev.Location;
  vcal.SaveToFile('myevent.ics');
  vcal.Free;
end;
We believe that this example once again proves how powerful TMS WEB Core is. Our demo can be accessed online by clicking the button below and don't forget that this is a PWA, so you can add it to the home screen of your mobile device!



We also decided to make this TWebvCalendar component available through our TMS WEB Core Partner program just like we did with TWebQRCode and TWebZip components. You can download it for free from here. The full source code of the demo is also available in the download, so you already have a starting point if you want to create something similar for your web application!

To install, open, compile & install the package from the "Component Library Source" folder. This will install the design-time TWebvCalendar component.
For use at runtime, make sure that the "Core Source" folder is in your TMS WEB Core specific library path that you can set via IDE Tools, Options, TMS Web, Library path.


Request payments with QR codes in a TMS WEB Core application

$
0
0



After releasing our free TWebQRCode component for TMS WEB Core, we wanted to see if there is a way to make payments with QR codes. While most solutions rely on different services and API keys, there's one European standard that many banks adopted already in some European countries. If you are curious about the full list of supported countries and banks, please head over to scan2pay.info

This standard is called EPC QR code and it is actually nothing more than a structured content that can be used to initiate a SEPA credit transfer.
Structuring the content manually is OK for some people, but we went a step further and updated our TWebQRCode component so you can take advantage of EPC QR codes to request payments with as little effort as possible:

  • TWebQRCode.GenerateEPCCode is a new method with parameters based on the EPC QR guidelines. The mandatory fields are the BIC code, beneficiary name and beneficiary IBAN number.
    //Generate EPC QR code with mandatory fields
    WebQRCode1.GenerateEPCCode('BIC', 'Beneficiary name', 'Beneficiary IBAN number');
    //Generate EPC QR code to request 5.5 EUR payment
    WebQRCode1.GenerateEPCCode('BIC', 'Beneficiary name', 'Beneficiary IBAN number', 5.5);
  • TWebQRCode.CorrectionLevel is a new property where you can set the error level of the QR code. The error level determines how much of the QR code can be missing while keeping it readable. An EPC QR code must be generated with M error level. The GenerateEPCCode method takes care of the correct error level setting under the hood.
  • We also updated the JavaScript file that we use in the TWebQRCode component, so if you experience any issues after downloading the component again, please try to clear your browser cache first.
You can download the updated TWebQRCode component from our TMS WEB Core Partner page. We also created a small application to demonstrate how easy it is to use TWebQRCode to generate payment requests. You can check it out by clicking the button below!



There are some countries that adopted a different format. For example the Czech Republic and the Slovak Republic uses Short Payment Descriptor. While we are unable to test this, one of you might find the idea interesting enough to test it with our TWebQRCode component or to create your own component for it. 😉 And don't forget, if you have a component that's worth sharing with others then contact us, become a TMS WEB Core Partner and enjoy the benefits!

TMS WEB Core 1.5 Rimini tips & tricks

$
0
0



For building web client applications, TMS WEB Core has grown since its inception to an extremely rich framework offering RAD component based web development. Its possibilities are sheer unlimited and its functionality documented via an over 500 page developer guide, over 100 sample applications, lots of short videos, a video training of hours and hours of material by Wagner Landgraf and last but not least the TMS WEB Core book by Dr. Holger Flick.

And still there are so many interesting things to tell about the TMS WEB Core framework, hence this blog with tips & tricks.

TWebStringGrid cell customization

Today we offer a tip how TWebStringGrid cells can be extensively customized from code via cell CSS styles. TWebStringGrid is modeled after the VCL TStringGrid for making it intuitively familiar for Delphi VCL users. The grid basically offers fixed rows and columns, a row count, a column count and cells containing text and accessible via WebStringGrid.Cells[ACol,ARow]: string;

In the browser, this grid is rendered as a HTML table and in HTML table, each cell is a TD HTML element. And here it becomes interesting as the TD HTML element is programmatically accessible and its attributes and style properties can be customized. The Pascal class for a HTML element is TJSHTMLElement. From this class, attributes can be easily accessed via TJSHTMLElement['attributename']. The HTML element style properties can be accessed via TJSHTMLElement.style.setProperty('propertyname','value') or TJSHTMLElement.style.removeProperty('propertyname').

So, this brings us to custimizing TWebStringGrid cells. Crucial here is the access to the TD HTML element for a cell which can be accessed via WebStringGrid.CellElement[ACol,ARow]: TJSHTMLElement.

With this, we can use following code to set a background color, font color and font-style for a cell with style properties and the text alignment via the align attribute:
var
  td: TJSHTMLElement;
begin
  // set text in the first normal cell
  webstringgrid1.Cells[1,1] := 'Hello world';
  webstringgrid1.ColWidths[1] := 192;

  // get the HTML element for the first cell
  td := webstringgrid1.CellElements[1,1];

  // change the alignment attribute for the cell
  td['align'] := 'right';

  // change the style property
  td.style.setProperty('background-color','red');
  td.style.setProperty('color','yellow');
  td.style.setProperty('padding-right','4px');
  td.style.setProperty('font-weight','bold');
end;
As this opens the full possibilities of CSS, you can see you can go to extreme lengths to customize each grid cell. See this reference to all CSS properties available: https://www.w3schools.com/cssref/.

Adding controls in a TWebStringGrid cell

As we have access to the cell HTML TD element, this means we can also insert other HTML elements into the cell. For this, the browser API provides element.appendChild(childelement). Of course, we can create HTML elements directly and insert these in the cell this way, but it is so much more object / component oriented when we can create a TMS WEB Core framework control, set its properties and insert it in a cell. Note that every TMS WEB Core visual control has a reference to its container HTML element. This can be accessed via WebControl.ElementHandle. Knowing this, inserting a control into a WebStringGrid cell becomes easily:
var
  td: TJSHTMLElement;
begin
  // get the HTML element for the first cell
  td := webstringgrid1.CellElements[1,1];

  td.appendChild(mywebcontrol.ElementHandle);
end;
Let's create now a few controls (a checkbox, a button and an image) and insert these into grid cells:
var
  td: TJSHTMLElement;
begin
  td := webstringgrid1.CellElements[1,2];
  chk := TWebCheckBox.Create(Self);
  chk.ElementPosition := epRelative;
  chk.TabStop := false;
  chk.Parent := WebStringGrid1;
  chk.Caption := 'check';
  chk.OnClick := ChkClick;
  td.appendChild(chK.ElementHandle);

  td := webstringgrid1.CellElements[1,3];
  btn := TWebButton.Create(Self);
  btn.ElementPosition := epRelative;
  btn.Caption := 'Click';
  btn.Parent := WebStringGrid1;
  btn.OnClick := BtnClick;
  td.appendChild(btn.ElementHandle);

  img := TWebImageControl.Create(Self);
  // "users.png" is an image added to the project that will be deployed to the output folder 
  img.URL := 'Users.png';
  img.ElementPosition := epRelative;
  img.HeightStyle := ssAuto;
  img.WidthStyle := ssAuto;
  img.parent := WebStringGrid1;
  td := webstringgrid1.CellElements[1,4];
  td.appendChild(img.ElementHandle);
end;
Note that we are setting the control's ElementPosition to epRelative here to make the control just flow in the grid cell. We also assign an event handler for the control's OnClick event. This is declared in the web form as:
  TForm1 = class(TWebForm)
  public
    { Public declarations }
    procedure BtnClick(Sender: TObject);
    procedure ChkClick(Sender: TObject);
  end;
The result of this customization in a default TWebStringGrid becomes:


What about TWebTableControl?

TWebTableControl is an alternative to TWebStringGrid for displaying 2 dimensional data. It differs from TWebStringGrid that it has auto flowing columns and rows. The good news is that in terms of customizing the cells of a TWebTableControl, it is 100% identical to TWebStringGrid. A cell element can be access via WebTableControl.CellElements[ACol,ARow]: TJSHTMLElement and from there you can do exactly the same as with a TWebStringGrid.

Using CSS classes

It might be desirable to group various cell properties into a CSS class and directly set the same CSS class for multiple cells. You can declare in your project HTML file following CSS:
.redcell { background-color:red; color:white; font-weight: bold;}
.yellowcell { backgrond-color:yellow; color:black; 
and then you can assign this to cells via:
var
  td: TJSHTMLElement;
begin
  td := webstringgrid1.CellElements[1,1];
  td['class'] := 'redcell';

  td := webstringgrid1.CellElements[2,1];
  td['class'] := 'yellowcell';
end;
Alternatively, you can also do this via an event handler, WebStringGrid.OnGetCellClass:
procedure TForm1.WebStringGrid1GetCellClass(Sender: TObject; ACol,
  ARow: Integer; AField: TField; AValue: string; var AClassName: string);
begin
  if (ACol = 1) then 
     AClassName := 'redcell';
  if (ACol = 2) then 
     AClassName := 'yellowcell';
end;
This way, we have defined for all cells in column 1 to use the 'redcell' CSS class and for all cells in column 2 the 'yellowcell' CSS class.

And for any other visual controls?

As explained, the container HTML element for each visual control is accessible via control.ElementHandle: TJSHTMLElement. This means we can manipulate CSS for the container HTML element via:
control.ElementHandle.style.setProperty('propertyname','value');
If a visual control is built-up from several HTML elements, either the control will offer access to these child HTML elements via a property to you can directly get access to any HTML child element via:
var
  i: integer;
begin
  for i := 0 to control.ElementHandle.childElementCount - 1 do
  begin
    TJSHTMLElement(control.children.items[i]).style.setProperty('propertyname','value');
  end;
end;
I hope you can get the picture that TMS WEB Core really opens the whole web browser world to your Object Pascal programming skils and that no area of UI controls is closed for your customization!

If you have not discovered TMS WEB Core yet, maybe you still have a few #staycation days left to allocate some time to explore it via the trial version. The nice thing about these tips and tricks is that these are applicable both to TMS WEB Core for Delphi/Lazarus and also to TMS WEB Core for Visual Studio Code. So, you can open up your favorite IDE and start your adventures in the web world.

Small XLSX component to deal with Excel files in TMS Web Core applications

$
0
0



Many times a quick and easy way is needed to export some basic data from a grid into an Excel file. We all know that Excel has lots of various features and covering the offered functionalities would require a huge library that we probably don't need for smaller tasks. We wanted to create something for these smaller tasks that covers reading, editing and writing Excel files locally in the client application while avoiding the complexities of a huge library.

TWebXLSX

TWebXLSX is a new free non-visual component as a wrapper around the open-source ExcelJS JavaScript library. Keep in mind, that ExcelJS only supports XLSX format.

Loading an excel workbook is as easy as calling TWebXLSX.Load with an array buffer as a parameter. In case of a TWebFilePicker, loading an XLSX file looks like this:
procedure TForm1.WebFilePicker1Change(Sender: TObject);
begin
  if WebFilePicker1.Files.Count > 0 then
    WebFilePicker1.Files.Items[0].GetFileAsArrayBuffer;
end;

procedure TForm1.WebFilePicker1GetFileAsArrayBuffer(Sender: TObject;
  AFileIndex: Integer; ABuffer: TJSArrayBufferRecord);
begin
  WebXLSX1.Load(ABuffer);
end;
You can save the workbook by calling TWebXLSX.Save with the filename as a parameter, which will then download the file to the device of the user.

ExcelJS is a workbook manager and it does not provide a visual element to display the data that it contains. Because of this, we added a Grid property where you can assign a TWebStringGrid or a TWebTableControl depending on your needs. TWebXLSX will load the data from the first sheet of the workbook into the grid automatically. If you want to change between the different sheets, you can use the TWebXLSX.ActiveSheet string property to define the active sheet name. If you don't know what sheet names are available, you can loop through the TWebXLSX.SheetNames property to find them out.
procedure TForm1.WebXLSX1WorkbookLoaded(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to WebXLSX1.SheetNameCount - 1 do
    WebListBox1.Items.Add(WebXLSX1.SheetNames[I]);
end;
When you drop a TWebXLSX component onto the form, it creates an empty workbook. Sheets to this empty workbook can be added with TWebXLSX.AddNewSheet('sheetname'). Sheets can also be removed by calling TWebXLSX.RemoveSheet('sheename').
Sometimes a workbook contains sheets that don't have any data. You can detect if a sheet has any rows by calling TWebXLSX.IsEmptySheet('sheetname').

When it comes to saving a workbook, you might want to apply some basic cell formatting. For this you can implement the OnSaveCell event which is triggered for each cell when the active sheet is saved (e.g. changing sheets or saving the workbook). With this event, you have direct access to the underlying ExcelJS cell object. Check out the styling documentation of ExcelJS to see which style settings are supported. You can also check the core libexceljs.pas file to see which properties we mapped already. If something that you'd like to use is missing, you can always extend it yourself!
procedure TForm1.WebXLSX1SaveCell(Sender: TObject; ARow, AColumn: Integer;
  AContent: string; var ACell: TJSExcelJSCellRecord);
begin
  if ARow = 0 then
    ACell.cell.style.alignment.horizontal := 'center';
end;
Would you like to customize your TWebStringGrid or TWebTableControl to reflect what's in your Excel file? You can also do that within the limits of the ExcelJS library by implementing the OnLoadCell event. Similarly to the OnSaveCell event, you have access to the underlying ExcelJS cell object that you can use to detect different cell types and styling. If you are not sure how to customize your grid, then take a look at our TMS WEB Core 1.5 Rimini tips & tricks blog.

And last but not least, you can use the OnWorkbookLoaded event when a workbook has finished loading, the OnSheetLoaded event when a sheet has finished loading into the grid and the OnNewSheetAdded event when a new sheet is added to the workbook.

Are you interested to see the TWebXLSX component in action? Check out our demo by clicking the button below!


As mentioned at the beginning of the artice, TWebXLSX is a free component that we are releasing as part of our TMS WEB Core Partner program and you can download it from here!

To install, open, compile & install the package from the "Component Library Source" folder. This will install the design-time TWebXLSX component.
For use at runtime, make sure that the "Core Source" folder is in your TMS WEB Core specific library path that you can set via IDE Tools, Options, TMS Web, Library path.


Newest book about TMS FNC Maps is ready

$
0
0


In April this year, we were pleased to release our new product TMS FNC Maps and announce it. TMS FNC Maps bundles all our expertise with using mapping services, with writing cross-platform and cross-framework Delphi code as well as building components for TMS WEB Core web client applications. From the beginning, we made the radical decision to base this work on the new operating system browser Edge Chromium from Microsoft for the Windows platform (where we already use Safari for iOS and macOS and Chrome for Android). From the very beginning of this development, our chief evangelist Dr. Holger Flick was involved and could play with internal versions and give feedback and steer the development.

This week all pieces of the puzzle fall together. After months of intensive work and collaboration with our development team, the new book from Holger, "Hands-on with Delphi: FNC Maps", is ready for sale. A coincidence or not, but also from this week, the Edge Chromium version Microsoft automatically deploys to Windows 10 operating systems also reached the version needed to use TMS FNC Maps on Windows. So, this means, on Windows it is no longer necessary to download and install a developer specific version of Edge Chromium. But my colleague Pieter Scheldeman will reveal more details shortly. Today is about the brand new book!

If you want to integrate mapping services' functionality such as from Google Maps, Bing Maps, Openstreet Maps, Here maps, TomTom maps, Azure maps in a Windows VCL application, a cross platform FireMonkey application or a TMS WEB Core web client application, TMS FNC Maps addresses it all and the new book covers developing with TMS FNC Maps in great detail over close to 400 pages.

Content

  • Get to know the FNC framework, FNC Core, and FNC Maps in a nutshell.
  • Learn about FNC Maps in detail: You will find dozens of hands-on examples from installation to modern multi-tier applications with large databases, web services, web, and desktop clients.
  • Annotate maps and visualize data using markers with clustering, lines, shapes, pop-up windows and routes.
  • Build applications that can handle any geographical data and interact with other Geographic Information Services (GIS). Load GPX tracks from GPS devices, GeoJSON shapes, and Google Earth-specific KML layers.
  • Include other mapping services to get directions with turn-by-turn instructions, to geocode addresses, and to determine your geolocation.
  • Create reports with a customizable template based on data from maps and databases.
  • Allow users to freely customize maps using events or interactive markers and shapes.

The examples in the book make use of:

Embarcadero Delphi Sydney 10.4 or newer suggested. Trial versions and free developer accounts of service providers suffice to run the examples. SQLite database examples are ready for use without server setup. Basics for reporting, web, and XData explained in “TMS WEB Core: Web Application Development with Delphi” and previous Hands-On titles are not included again but referenced.

How to order



TMS Subscription Manager v2.1 released

$
0
0

One tool, one place to help our customers having purchased product bundles find, install, update, get info about and renew the products, that is what TMS Subscription Manager is about.

This new version brings:

  • One click to see product version information
  • One click to go directly to your account on our website
  • See if older product versions are on your system and revert to older version when needed
  • Actualized direct links to our new support center or social media
  • Adapt folder where the downloads are kept
  • Actualized to our latest brand graphics
TMS Subscription Manager is of course a 100% native Delphi created Windows client and will automatically update to v2.1 thanks to our own TWebUpdate technology and uses several TMS VCL UI Pack components like our grid.





TMS Subscription Manager is designed to work with our product bundles: TMS ALL-ACCESS, TMS VCL Subscription, TMS Component Studio, TMS FNC Component Studio, TMS FMX Component Studio.

Want to checkout the latest status of your purchased product subscriptions on the go, we also have TMS Subscription Dashboard! This is a 100% TMS WEB Core created progressive web application that works fine in desktop and mobile browsers thanks to responsive design and can be installed as application also on your iOS or Android smartphone or tablet thanks to the built-in PWA technology.



Edge Chromium Stable Support!

$
0
0

Stable



Microsoft has just released v85.0.564.41 into the stable build and therefore we can now officially announce that our TAdvWebBrowser component is working without the need for an additional browser installation! Up until now, it was necessary to install an additional browser from one of the insider channels (beta, dev, canary). As the previous versions were introducing breaking changes, we decided to build our API wrappers against a more stable version and allow more time for testing. Today the day has come that we can just use the TAdvBrowser against the stable build, out of the box. This means that all insider builds can be uninstalled, and you can deploy your application to an up-to-date Windows 10 environment. That's right, the Microsoft Edge Chromium browser should automatically be installed on any Windows 10 machine.



TMS VCL UI Pack 10.4 & RAD Studio 10.4.1

The TMS VCL UI Pack 10.4 update is adding support for the Microsoft Edge Chromium stable version, so go ahead and download the latest available release and start exploring the possibilities of the browser. Note that the WebView2Loader_x86.dll and the WebView2Loader_x64.dll are still a necessary deployment for communication between client and browser. Please follow the steps at this page. We can also confirm TAdvWebBrowser in combination with Edge Chromium has been tested and is working on RAD Studio 10.4.1.

More features coming in the near future

The features that are currently existing are:
  • Navigate to an URL
  • Load HTML
  • Debug through the developer console
  • Add a JavaScript to client bridge
  • Capture a webpage screenshot
  • Execute JavaScript code with support for asynchronous callbacks
We'll keep exploring the exposed APIs and add more features to our browser implementation in the future.

What about FNC?

We are currently applying a lot of smaller improvements, and are testing new features for TMS FNC Maps. As this process takes time and we also want to make sure to properly test the stable release against our FNC components, we plan on releasing an FNC update next week. Stay tuned!

TMS WEB Core for Visual Studio Code v1.0 released

$
0
0

After an intensive development and beta cycle, we are proud to announce the release of TMS WEB Core for Visual Studio Code v1.0 today! Visual Studio Code is the 3rd IDE that can host the TMS WEB Core framework for web client application development after the earlier released versions for Delphi and Lazarus. TMS WEB Core offers Object Pascal software developers visual RAD component-based web client development with the strongly typed and object-oriented Pascal language.



TMS WEB Core for Visual Studio Code brings exciting new capabilities


  • WYSIWYG visual designer. The designer is a web view and renders HTML/CSS from controls and/or templates “as is” in the IDE.
  • Cross-platform IDE. TMS WEB Core for Visual Studio Code runs directly on Windows, macOS, and Linux.
  • Debugging from the IDE. Debugging of applications running in the browser is possible from the Visual Studio Code IDE itself.
  • Uses the OmniPascal Visual Studio Code extensions for fast code completion and syntax highlighting.
  • Integrated online-help. Press F1 with a component, property or event selected and help shows up in the IDE.
  • High-DPI/Retina enabled IDE. Razor sharp code and designer on any screen.
  • Optional TMS WEB Core distribution via the Microsoft Visual Studio Code marketplace.

The TMS WEB Core framework used in TMS WEB Core for Visual Studio Code product is identical to the framework used in the Delphi or Lazarus IDE. This means existing Delphi projects can be opened and worked on from Visual Studio Code and vice versa.

TMS WEB Core for Visual Studio Code brings an unparalleled web development productivity


  • Large number of included visual and non-visual components: With these components, a RAD approach allows you to build solutions fast.
  • Visual data-binding: A data-binding mechanism similar to Delphi VCL data-binding enables to hook-up your client application via client datasets to data sent from a REST API based backend quickly.
  • Use existing or custom HTML web templates: The Visual Studio Code IDE has built-in strong support for editing HTML/CSS and a vast array of extensions. This adds even more power to it. The visual designer shows the pages ”as is” using the templates.
  • Integrate any existing JavaScript library: The underlying pas2js compiler for transpiling Object Pascal code to JavaScript code running in the browser facilitates programmatic access to any existing JavaScript library. This opens up the huge availability of all kinds of easily available web functionality to integrate.
  • Debug using Object Pascal code: All modern debugging capabilities like breakpoints, watches, stepping in code, ... can be done in the Object Pascal code base from the Visual Studio Code IDE.


With this first release, we embark on an exciting adventure with the mission to bring Object Pascal developers a fast, productive, feature-rich, and enjoyable web development experience. Version 1.0 is the first step, and our team is already working on follow-up versions we will release shortly. This includes:

  • Built-in PWA project creation support.
  • Built-in Electron cross platform desktop application development support.
  • Installable 3rd party component support, including full usage of the TMS FNC component offerings.
  • New Object Pascal language features support.
  • Modern project creation wizards.
  • ... and many more

Get in the front seat today


Take a head start now and get TMS WEB Core for Visual Studio Code at our launch price starting from 295EUR for a single developer license or download and explore this new ground-breaking product using the trial version!

TMS FNC Maps updates!

$
0
0

Intro



In April, we released the first version of TMS FNC Maps. Now 4.5 months later we have released v1.1 with exciting new features and improvements.

  • TTMSFNCDirections: TravelMode tmPublicTransport, tmTruck added (for supported services)
  • TTMSFNCDirections: GetDirections result Status and ErrorMessage added
  • LoadGPXFromFile/LoadGPXFromStream/LoadGPXFromText now also supports elevation and timestamp data
  • Events OnCreateGPXTrack, OnCreateGPXSegment for creating your own data structure when parsing GPX files
  • TTMSFNCGoogleMaps: Clusters.Text property
  • TTMSFNCGeoCoding: Get(Reverse)Geocoding result Status and ErrorMessage added
Internally, a lot of smaller improvements have been made in combination with the existing supported services, TMS FNC Core and TTMSFNCWebBrowser.

Edge Chromium



Last week we also announced Edge Chromium Stable support for TAdvWebBrowser. We can now also announce that the TTMSFNCWebBrowser has been synchronized and offers Edge Chromium stable support. More details on how to install Edge Chromium can be found here.

TMS FNC Maps Book



TMS FNC Maps offers a demo and documentation to get you started, but if you really want to energize your developments the TMS FNC Maps Book is a must have!

Stay tuned for more!

TMS FNC Maps 1.2 is already around the corner with more exciting new features, so stay tuned and keep an eye on this blog .

Online event: The Theory and Practice of Amazing Desktop Application UI & UX

$
0
0



We look forward to connect with you at the upcoming conference! TMS evangelist Holger Flick and many other experts will share their knowledge with the audience! Take your Desktop UI/UX to new levels as you learn from industry leaders alongside over 1000 developers like you!

The Theory and Practice of Amazing Desktop Application UI & UX Is a FREE online event, organized by Embarcadero technologies, on Sept 16th & 17th, 2020.

The full schedule can be found on the following page https://summit.desktopfirst.com/schedule/

Speakers

https://summit.desktopfirst.com/speakers/

The speakers will be sharing their experiences, strategies, and knowledge. You can choose between multiple speakers and categories.

TMS evangelist Holger Flick "Building consistent UI suitable for high DPI with vector images and styles"

Since 1996, Dr. Holger Flick has been using Delphi as his primary development platform and has been an active member of the community. He studied computer science at Dortmund University and later wrote his dissertation at the Ruhr University in Bochum in the field of telemedicine. For his passion for and knowledge of Delphi he was awarded the “Delphi MVP” moniker in 2016. In 2019, Holger moved to the United States of America (USA) and established his new company FlixEngineering LLC. The company focuses on consulting, training and software development using object-oriented programming languages like Delphi, C#, Swift, and Objective-C. Holger is part of the TMS Software family providing his expertise as Evangelist and QA Engineer.

Holger Flick has written multiple book on TMS software: Participants can choose from multiple categories depending on their interest: https://summit.desktopfirst.com/topics/

Book your tickets today and reserve your seat: book now

Get started with TMS WEB Core for Visual Studio Code

$
0
0



The first version of TMS WEB Core for Visual Studio Code v1.0 has been released! Visual Studio Code is the 3rd IDE that can host the TMS WEB Core framework for web client application development after the earlier released versions for Delphi and Lazarus. TMS WEB Core offers Object Pascal software developers visual RAD component-based web client development with the strongly typed and object-oriented Pascal language.

For developers who are not yet used to Visual Studio Code, this is a completely new world. That’s why here is a starting guide, with all the information you need to get started!

Get started with TMS WEB Core for Visual Studio Code

TMS videos Videos: José Leon Serna (chief architect)
YouTube channel Blog articles Books Online courses
With version 1.0 the first step has been taken and further developments are being made to expand this into a very productive and rich platform.

TMS WEB Core for Visual Studio Code is now available at our special launch price starting from 295EUR for a single developer license! And you can also download and explore this new ground-breaking product using the trial version!

Follow us on social media and don't miss our blogs!




TMS WEB Core Academic is here for Delphi developers!

$
0
0



This year in February, we launched TMS VCL UI Pack Academic. In April, we launched TMS FNC UI Pack Academic. And now in September, we launch TMS WEB Core Academic!

TMS Academic program


With TMS VCL UI Pack Academic, we want to inspire and motivate students and teachers to learn about the power of the Delphi VCL framework and help users to build even more powerful, visually pleasing, and feature rich Windows desktop applications.

With TMS FNC UI Pack Academic, we want to do the same for FMX cross platform applications. Empower students and teachers to discover the fascinating world of cross platform development with Delphi and the FireMonkey framework. TMS FNC UI Pack delivers over 70 extra sophisticated cross platform/cross framework visual controls to enrich native applications created with Delphi for Windows, iOS, macOS and Android. And now, with the third step, we want to motivate students and teachers to discover that Delphi can also be an extremely productive tool for web client application development.

TMS WEB Core Academic


TMS WEB Core , offers RAD component based visual development of web applications driven by the strongly typed and object-oriented Object Pascal language from the familiar and beloved Delphi IDE. It is clear that with the first three academic editions of our popular products, we hope students will enjoy picking up Delphi and experience how powerful it is and how it makes software development fun at the same time. With that, we want to offer our contribution to nurture the next generation of enthusiast and passionate Delphi developers.

As all our other academic releases, it is designed for use with the latest and greatest Delphi version, now v10.4.x Sydney. In order to obtain the academic licensed version of TMS WEB Core, students and teachers need to provide an academic email address and their school or university information. In addition to the fully functional academic version of TMS WEB Core, there is plenty of information to learn about TMS WEB Core and to get started.

Getting started


Manual:

TMS WEB Core Developers Guide


Demos:

TMS WEB Core demos


Videos:

TMS WEB Core videos


Books:



TMS WEB Core: Web Application Development with Delphi


Training class:


courses.landgraf.dev

Next level:
And for those students who want to rise to the next level, there is the TMS WEB Core partner program! Develop your own components or Object Pascal interfaces to existing JavaScript libraries and publish these via the TMS WEB Core partner program. Contributing partners will get the regular TMS WEB Core version with a license that permits to use it with Delphi IDEs XE7 to 10.4 including Lazarus on Windows, macOS, and Linux but also with our brand new TMS WEB Core for Visual Studio Code that can be used also from all three major desktop operating systems.

It speaks for itself that we are enthusiastic to see students and teachers "go web" and we are more than curious to see what exciting, new, and innovative solutions will surface. With all that, you will move your career forward, move Delphi forward, and move TMS WEB Core forward!

Request the academic license now!

Don’t wait for the perfect moment. Take the moment and make it perfect. Request your academic license here: https://www.tmssoftware.com/academic





Hands-on: Building web design for a RAD Studio TMS WEB Core project

$
0
0

I have been a Delphi developer since 1996. During this journey, I have learned new skills and acquired new tools to keep up with the demands of the the software market. In the early 2000s, I learned about AJAX, web services, and basic web design. However, my studies did not require extensive software development for the World Wide Web, and I was happy to go back to developing user interfaces with Delphi in the VCL.

Times have changed significantly since then, and I have to be honest that right now I am still learning about web design for modern web development each day. It has become a major part of my daily routine to learn one new aspect of web development each day. I consider web development a mandatory tool in every software developer's tool belt. Basic web design skills go just along with it.

If you struggle with HTML and CSS just as much as I, look no further. I might just have the video tutorial you need. The best thing about it: It's free. It will start right at the beginning.

From the perspective of a Delphi developer, you will learn step-by-step how to build my application that I built to make ordering my books easier.

As you can see, you can select the store and book title you want to order and the application will navigate to the page for you where you can order the book.

Very simple. Or really? Three months ago, the design of the page would have been an impossible thing to do.

You will learn about:

  • Separating application development with TMS WEB Core and web design
  • Bootstrap
  • FontAwesome
  • Using (free) plugins in Visual Studio Code for web design
  • Emmets and code completion for web design with Visual Studio Code
  • WYSIWYG of your web design in the web browser
  • Link you web design to your application controls
If you have a TMS WEB Core license and use RAD Studio, this tutorial will get you started how to develop web applications with external web design. For the external web design, we will use Visual Studio Code.

If you like this tutorial and the hands-on approach, you will find more examples of this type in the book series. You can use the form above to learn more about each book title on Amazon.



Holger Flick




Documenting your Delphi REST API the easy way

$
0
0

Create documentation is boring. At least that's my opinion, and most developers I know also don't like to write it. But that's something we need to do, of course. Thus, the easiest it gets to document things, the better.

Photo by Aaron Burden on Unsplash

With TMS XData, you create your REST API server using Delphi very easily, but you also get it documented almost automatically using the automatic Swagger generation feature. Since all endpoints are strong typed in server, all it takes is just to enable a single property and have your endpoints listed and testable. This feature has been available for years already.

But now XData takes it to another level. A good (if not the best) way to document your source code is to use XML Documentation Comments. In the interfaces and methods that build your service contract, you can simply add specific XML tags and content, like this:

    /// <summary>
    ///   Retrieves the sine (sin) of an angle
    /// </summary>
    /// <remarks>
    ///  Returns the Sine (Sin) value of an angle radians value.
    ///  The value returned will be between -1 and 1.
    ///  If the angle is zero, the returned value will be zero.
    /// </remarks>
    /// <param name="Angle">
    ///   The angle in radians.
    /// </param>
    function Sin(Angle: Double): Double;

And Delphi IDE will automatically use it for Help Insight , showing you information about the method on-the-fly. For example, if some developer is trying to use the Sin method of your API, information will be conveniently displayed:

xdata-xml-help-insight


The good news is that, with XData, you can use such XML comments in the Swagger document and Swagger-UI that are generated automatically by XData, improving even more your REST API documentation. Since the API endpoints are generated directly from the interfaced and methods, XData knows exactly the meaning of each documentation and can map it accordingly to Swagger.

By asking Delphi to generate the XML documentation files, and using a single line of code like this:

uses {...}, XData.Aurelius.ModelBuilder;
 ...
   TXDataModelBuilder.LoadXmlDoc(XDataServer.Model);

XData will reuse the documentation and include it in Swagger:

xdata-xml-help-insight


Using different documentation for Help Insight and Swagger

Reusing the same XML comments is nice as you don't repeat yourself. Document your code just once, and the same documentation is used for documenting your Delphi interfaces (Delphi developments) and your REST API (API consumer development).

But, if for some reason you want to use different documentation content for Delphi developers and for REST API users, that's also possible. For example, suppose the following documentation:


Note that tags summary and param are the regular XML documentation tags. They will be used for Help Insight:

xdata-xml-help-insight-2


And swagger tags with no name attribute (A), or name param-A (B), param-B (C) and remarks (D) will be used exclusively for Swagger documentation:

xdata-xml-swagger-example-2


Customizing tags

You can also customize the tags in Swagger. Endpoints are grouped together inside a tag, which can have a name and description.

By default, the name of the tag will be path segment of the interface service. But you can change it using either swagger tag using tag-name attribute.

The description of the tag by default is empty, but you can define it using the regular summary tag, or optionally using the swagger tag with tag-description attribute.

Consider the following documentation for both IArithmenticService and ITrigonometryService :

xdata-xml-tag-source


The above tags will generate the following output in Swagger UI:

xdata-xml-swagger-tags



Customizing document header and description

XData also takes the model name, version and description into account to build the final document. You can configure such settings directly by changing some properties of the XData model:

  XDataServer.Model.Title := 'Mathematics API';
  XDataServer.Model.Version := '1.0';
  XDataServer.Model.Description :=
    '### Overview'#13#10 +
    'This is an API for **mathematical** operations. '#13#10 +
    'Feel free to browse and execute several operations like *arithmetic* and *trigonometric* functions'#13#10#13#10 +
    '### More info'#13#10 +
    'Build with [TMS XData](https://www.tmssoftware.com/site/xdata.asp), from [TMS Software](https://www.tmssoftware.com).' +
    'A Delphi framework for building REST servers'#13#10 +
    '[![TMS Software](https://download.tmssoftware.com/business/tms-logo-small.png)](https://www.tmssoftware.com)';

Note that you can use Markdown syntax to format the final text. Here is what it will look like:

xdata-swagger-doc-description


You can read more about using XML documentation in Swagger with TMS XData by referring to the official documentation page.


Finally, this video shows in details how REST/JSON documentation works with XData, explaining how Swagger and Help Insight documentation is built from single source, how XML comments can be used, and even more. Lots of useful information there!




TMS FNC UI Pack v3.2 Revealing some highly anticipated components

$
0
0

We already have an extensive set of powerful and feature-rich UI controls in our TMS FNC UI Pack. But there is always room for some additional tools to help you with your cross framework and cross platform work. In this new release of our TMS FNC UI Pack we’ve added 5 new components which were requested by you, our community of great developers who see the enormous advantages of components that can be used on VCL, TMS Web Core, FMX and Lazarus with just one code base.

TMS FNC Controls can be simultaneously used on these frameworks:


TMS FNC Controls can be simultaneously used on these operating systems/browsers:


TMS FNC Controls can be simultaneously used on these IDE's:


New to the TMS FNC UI family

TTMSFNCRichEditorHorizontalRuler




TTMSFNCRichEditor has a ruler control that can be connected to it. This control has the intuitive handling that you are familiar with from the advanced text editors. With this ruler you can easily control the margins of your page and the indentation of your text. And you have the ability to add tabs, which sets the position of your text when the next tab is pressed. This component is a great advantage to get your text document to a higher level as it helps you with the layout of your text.

TTMSFNCSplitter




Our TTMSFNCSplitter has the same behavior as other splitters, but as this is a FNC control, you can use the same component on all the different platforms. No more need to set framework specific properties. Next to this timesaving feature, we have made the appearance customizable to your preferences, so the control can blend in with your application.

TTMSFNCProgressBar




One of the most requested components is the TTMSFNCProgressBar, this provides users with visual feedback about the progress of a procedure within an application. With more than 25 properties to set the appearance and layout of the component, you have a huge range of possibilities to customize your TTMSFNCProgressBar. And by changing the minimum and maximum value, you can easily invert the direction of the progress.

TTMSFNCRating




While we were creating the TTMSFNCProgressBar, we noticed that it might be nice to have a similar control with interaction. Therefor we created TTMSFNCRating. With the use of images (SVGs as well) you can set a scale to give a rating. If you clear the images, the control will look like a TTMSFNCProgressBar but with the ability to interact with it. This can be done by clicking on the value that you want, sliding from the end of the progress to where you want or via your keyboard with the arrow keys.

TTMSFNCWaitingIndicator




An indicator for illustrating an indefinite waiting time for a task that is in progress. You can choose if you want show a progress or if you want circles, squares or images moving around a center bitmap or if you want them to change size. In case you want to show that a form or a panel is currently not available, you can center the waiting indicator over the parent and use an overlay to emphasize this.

If you want to see some other examples or the behavior of the FNC splitter and rating control, you can have a look at the following video:


From Windows Certificate Store to TMS Cryptography Pack TX509Certificate component.

$
0
0

TX509Certificate is a component of TMS Cryptography Pack to use X509 certificates. With it, we can sign certificate signing request (CSR) or use it in XAdES, CAdES or PAdES to sign or verify documents.

We can generate self-signed certificates, import them from PEM file, from PEM string, from PFX file.

In this post, I will explain how to import certificate from Windows Certificate Store.

To do that, we have to use the crypt32 DLL and CertOpenSystemStore and CertFindCertificateInStore.

CertOpenSystemStore

function CertOpenSystemStore(hProv: HCRYPTPROV; szSubsystemProtocol: LPCTSTR)
 : hCertStore;

This function is used to open the certificate store. The microsoft documentation is here.
The first parameter hProv is not used and should be set to NULL. The second parameter is a string that names a system store. Most common options are:



You can use CertEnumSystemStore function to list the names of existing system stores. The function returns an handle to the store. CertFindCertificateInStore
function CertFindCertificateInStore(hCertStore: hCertStore;
 dwCertEncodingType, dwFindFlags, dwFindType: DWORD; pvFindPara: Pointer;
 pPrevCertContext: PCCERT_CONTEXT): PCCERT_CONTEXT;

The function finds a certificate in a given store. The Microsoft documentation is here. The first parameter is the handle of the store, returned by CertOpenSystemStore. The second parameter is the encoding type of the cert. The options are:
  • X509_ASN_ENCODING
  • PKCS_7_ASN_ENCODING
We will use only X509_ASN_ENCODING because it is the certificate encoding type.

The third parameter is used with some dwFindType values to modify the search criteria. For most dwFindType values, dwFindFlags is not used and should be set to zero.

The fourth parameter specifies the type of search being made. For the complete list of options, you can read the documentation. We will use in this example the CERT_FIND_SUBJECT_NAME option, to search from subject name of the certificate.

The fifth parameter contains the content of the search. In your example, it will contain the subject name of the certificate we want.

The sixth parameter is a pointer to the last CERT_CONTEXT structure returned by this function. This parameter must be NULL on the first call of the function. To find successive certificates meeting the search criteria, set pPrevCertContext to the pointer returned by the previous call to the function. If the function succeeds, the function returns a pointer to a read-only CERT_CONTEXT structure. A CERT_CONTEXT structure is:

_CERT_CONTEXT = record
    dwCertEncodingType: DWORD;
    pbCertEncoded: LPBYTE;
    cbCertEncoded: DWORD;
    pCertInfo: PCERT_INFO;
    hCertStore: hCertStore;
  end;

dwCertEncodingType is the encoding type of the certificate, pbCertEncoded is the content of the certificate, cbCertEncoded is the length of the certificate, pCertInfo is the certificate information and hCertStore is the store.

Code
The code to import a TX509Certificate from the Windows Certificate Store is the following:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  CryptBase, X509Obj, MiscObj;

const
  X509_ASN_ENCODING = $00000001;
  CERT_FIND_SUBJECT_STR = 8 shl 16 or 7;  // values taken from System.Net.HttpClient.Win

type
  HCRYPTPROV = ULONG_PTR;

  _CERT_CONTEXT = record
    dwCertEncodingType: DWORD;
    pbCertEncoded: LPBYTE;
    cbCertEncoded: DWORD;
    pCertInfo: PCERT_INFO;
    hCertStore: hCertStore;
  end;

  PCERT_CONTEXT = ^_CERT_CONTEXT;
  PCCERT_CONTECT = PCERT_CONTEXT;

  function ExtractCertWindowsStore(subjectName: string): TX509Certificate;

  function CertOpenSystemStore(hProv: HCRYPTPROV; szSubsystemProtocol: LPCTSTR)
    : hCertStore; stdcall; external 'crypt32.dll' name 'CertOpenSystemStoreW';

  function CertFindCertificateInStore(hCertStore: hCertStore;
    dwCertEncodingType, dwFindFlags, dwFindType: DWORD; pvFindPara: Pointer;
    pPrevCertContext: PCCERT_CONTEXT): PCCERT_CONTEXT; stdcall;
    external 'crypt32.dll' name 'CertFindCertificateInStore';

implementation

{$R *.dfm}

function ExtractCertWindowsStore(subjectName: string): TX509Certificate;
var
  Store: hCertStore;
  Cert: PCCERT_CONTEXT;
  s: string;
  i: integer;
  Conv: TConvert;
  X509Cert: TX509Certificate;
begin
  Cert := nil;
  Store := CertOpenSystemStore(0, PChar('MY'));
  if (Store <> nil) then
    Cert := CertFindCertificateInStore(Store, X509_ASN_ENCODING, 0,
      CERT_FIND_SUBJECT_STR, PChar(subjectName), nil)
  else
     raise Exception.Create('Unable to open certificate store');

  if (Cert <> nil) then
  begin
    s := '';
    for i := 0 to Cert.cbCertEncoded - 1 do
      s := s + IntToHex(integer(Cert.pbCertEncoded[i]), 2);

    Conv := TConvert.Create(hexa);
    try
      s := Conv.HexaToBase64(s);
    finally
      Conv.Free;
    end;
    X509Cert := TX509Certificate.Create;
    X509Cert.CrtStr := s;
    X509Cert.Decode;
    Result := X509Cert;
  end
  else
    raise Exception.Create('Certificate ' + subjectName + ' not found');
end;

end.



Viewing all 1006 articles
Browse latest View live


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