Blog


Most Recent Post  |  Next Post  |  Previous Post  |  Index List

Video: Accessing any Delphi compatible database through a REST API using SQL

Bookmarks: 

Monday, May 20, 2019

I have expressed this before, but Delphi is and will hopefully always be the number one programming language for database-driven applications. The architecture that has been there since Delphi 1 is still standing strong. Of course, there has been need for change to the database drivers, due to technological advances. However, at the inner core the classes TDataset and TDataSource as still standing strong.

Web Applications, multi-platform development, and mobile platforms make it necessary to introduce a layer in between the database and the application. Web Services producing JSON formatted data following the REST principle have become the pseudo-standard. As a side-note, REST is still not a standard and only a principle.

SQL is still the database query language that developers feel most comfortable with. The Web Service Layer introduces an insurmountable challenge for many. Thus, there are more frameworks than sand at the beach to facilitate the process. TMS Software offers a straightforward, affordable solution if you need to build a Web Service API with JSON called XData. If you look for performance, no need for JSON and a quick way to migrate your database project use RemoteDB from TMS instead.

For the case that you need a REST API with JSON support, I recorded the following video. It teaches you how to hook up any database supported by Delphi to the web service. You will then be able to offer any SQL query as a result for the web service. Further, you can even use parameters.

Stay tuned for more video content about RemoteDB. An even quicker and more efficient solution to provide abstract database support to your client applications. Abstract database support means in this case that the client is unaware which database you use and also will not need the database driver technology to access the data.

The video will explain step-by-step how to:
  • Create a web service with XData
  • Add the database connection to a FireDAC database
  • Add the database query
  • Add a service for the SQL queries
  • Write a VCL Forms client that displays the data
Be aware of the fact that the client will not need any XData-specific components.



Errata

The VCL client actually does not need to create the TStream instance as the XData framework does that. Thus, the correct client-side code is this:

LStream := LService.GetSchools as TMemoryStream

There is no need to do anything else with LStream.

Holger Flick


Bookmarks: 

This blog post has received 4 comments. Add a comment.



Video: Google Maps with Style

Bookmarks: 

Wednesday, May 15, 2019



Google Maps has become a very popular means to include mapping in business applications. In Delphi, we can use components from TMS Software that facilitate the use of the Google Maps API using Delphi components. Using the Google Maps API with these components is like using any other Delphi control.

The controls are available for:
  • VCL
  • FireMonkey (FMX)
  • Web (both TMS Web Core and IntraWeb)

Recently, Google introduced Map Styles. The style does not only refer to colors but also to content. You can define what is displayed and how. Further, the Google Maps API now comes with a “Night Style” for map display in dark user interfaces.

So far, TMS updated the VCL and FireMonkey controls to support styles. The following video instructs you how to:
  • Make use of pre-defined styles
  • Create your custom styles with the Google Style Designer
  • Use styles created by other Google Maps users




Holger Flick


Bookmarks: 

This blog post has not received any comments yet. Add a comment.



Why We Chose to Use TMS Components in AlignMix

Bookmarks: 

Tuesday, May 14, 2019



Choosing which components to use in your application is an important decision that warrants careful consideration. Wrong decisions can be costly.

We’ve been using Delphi to develop applications since Delphi 1.0 back in 1995; and before that Turbo Pascal. All our applications help companies manage their sales teams. Over the years we’ve made mistakes when selecting component vendors. From these mistakes we’ve learned our lesson. When we started developing AlignMix, our flagship sales territory mapping application, we had a clear set of principles for choosing which components we’d use. To give you some background, AlignMix was launched in 2016 and now has over 5,000 users. It has a minimalist design, with strong focus on delivering a beautiful user experience for our corporate clients.

Here’s our guiding principles:

1. Avoid Freeware:

This one is a little controversial since many developers prefer open source over closed source. But in our experience the Delphi world is full of hobbyist who create great components, make it freeware, develop it for a few years and then move on as their priorities change. Even if the source is available, we don’t want to spend our time maintaining someone else’s code. It’s different if the project has a large community of developers, but this is rare in the world of Delphi.

2. Partner with Companies Who Are Committed to the Delphi Platform:

We prefer to choose component developers who are clearly committed to Delphi. We don’t want to use components from companies that only dabble with Delphi. We want a company where the leadership is always thinking about new ways to help the Delphi community. This is one area where TMS really shines. I don’t know of any component vendor that is more committed to the Delphi platform than TMS.

3. Look for Companies that Quickly Support New Versions of Delphi:

It’s frustrating when a shiny new version of Delphi is released but you’re not able to upgrade simply because a component vendor takes its time to support the new version. Once again TMS is brilliant at quickly supporting each new version of Delphi. As soon as a new version is released you can be sure TMS will almost immediately publish a timetable showing when each of their products will support the new version.

4. Minimize the Number of Component Vendors You Use:

If you follow principles 1 to 3, you’ll most likely end up choosing just a few component vendors. That’s what we’ve done. And we’re reluctant to add any more. Thankfully TMS has a comprehensive range of components that cover almost all our needs. Look at the screenshots to see how they are used in AlignMix. We trust Bruno and his team and will be working with them for the foreseeable future.



If you’d like to see AlignMix you can find out more on the website.

Author: Steve Maughan

Masiha Zemarai


Bookmarks: 

This blog post has not received any comments yet. Add a comment.



The Story of an intern at TMSSoftware

Bookmarks: 

Monday, May 06, 2019

Hello, this is the intern speaking (or writing) about his experience at TMSSoftware. I’m a second year graduate student in programming-informatics who has been given the opportunity to do my internship here at TMSSoftware.

Getting started

My first week starting here was interesting as I had no real background experience in Delphi or Object Pascal, as the primary languages I learned at school were Java and C#. Thankfully, I had a lot of resources available, which includes the Object Pascal Handbook by Marcu Cantù. So getting started went smooth.

My internship was split up into three parts, were the first part was to study and test different REST services. The second part was based on implementing the APIs such as Google Translate and Microsoft Vision. The third part involved using the implementation in an application called TMS Vision.

TMS Vision should allow visually impaired people to be informed about their environment by simply tapping on their mobile phone and getting a spoken response in the native language. That response can be a series of keywords, or a short description on the object that has been recognized by the camera.

Used technologies

Doing my internship at TMSSoftware, I got access to the newest tools TMS had to offer. With the TMS FNC Cloud Pack I had the foundation to build a set of classes that implement the services needed to send and receive data via REST. For the GUI, I used FNC. For those not yet familiar with 'FNC' , these are what we call Framework Neutral Components. This means that these components can be simultaneously used with different frameworks, are fully cross platform, can be used from Delphi, C++Builder and Lazarus and most spectacularly can be used to create web applications with TMS WEB Core. Read more about FNC for the web here.

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:



Because TMS FNC Cloud Pack contains a core layer to handle asynchronous REST request, it became really easy to send and receive data.

Example of translating text via the Google Translate API. In the code below, the TTMSFNCSimpleCloudBase class allows you to quickly send and receive data via REST without OAuth 2.0 authentication flow requirements.
// form class private variables
private
  c: TTMSFNCSimpleCloudBase;
  target : string;

procedure TGoogleTranslateForm.Button1Click(Sender: TObject);
begin
  c.Request.Clear;
  c.Request.Host := 'https://translation.googleapis.com';
  c.Request.Path := '/language/translate/v2';
  c.Request.Query := 'q=' + TTMSFNCUtils.URLEncode(Edit1.Text) +'&format=text'+
   '&target=' + target + '&key=' + c.Authentication.Key;
  c.Request.Method := rmGET;
  c.ExecuteRequest(DoTranslate);
end;

Also parsing the request result data was very easy with TMS FNC Core, which exposes a set of ready to use functions for parsing JSON.
procedure TGoogleTranslateForm.DoGetList(const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  j, jd, ja, jav: TJSONValue;
  I: Integer;
  siso, sname: string;
  l: TLanguage;
begin
  lst.Clear;
  if ARequestResult.ResultString <> ''  then
  begin
    j := TTMSFNCUtils.ParseJSON(ARequestResult.ResultString);
    try
      jd := TTMSFNCUtils.GetJSONValue(j, 'data');
      if Assigned(jd) then
      begin
        ja := TTMSFNCUtils.GetJSONValue(jd, 'languages');
        if Assigned(ja) and (ja is TJSONArray) then
        begin
          for I := 0 to TTMSFNCUtils.GetJSONArraySize (ja as TJSONArray) - 1do
          begin
            jav := TTMSFNCUtils.GetJSONArrayItem(ja as TJSONArray, I);
            if Assigned(jav) then
            begin
              siso := TTMSFNCUtils.GetJSONProp(jav, 'language');
              sname := TTMSFNCUtils.GetJSONProp(jav, 'name');

(Code snippets were written for Google Translate in the first week of the internship) Here is an example to test the REST API for Google Translate.


Starting on components

After getting used to the different platforms, investigating and testing the various cloud services to be implemented in TMS Vision, I got started on transferring the sample code into components that work cross-platform. Doing the internship here, made this easy as the TMS FNC Cloud Pack already provided a solid base to work on, and additionally my colleagues were eager to lend their advice when I needed help.

Here is an example of how the final code looks with the Google Translate component.
procedure TGoogleTranslateForm.FormCreate(Sender: TObject);
begin
  c := TTMSFNCCloudGoogleTranslate.Create;
  TLanguage := TStringList.Create;
  c.Authentication.Key := 'My-API-Key';
  c.OnIsoLanguageList  := doLanguageList;
  c.GetSupportedLanguageList;
  c.OnTranslate := DoTranslate;
end;

procedure TGoogleTranslateForm.Button1Click(Sender: TObject);
begin
  if FTarget <> '' then 
    c.Translate(Edit1.Text, FTarget)
  else 
    c.Translate(Edit1.Text) ;
end;

This shows how compact your final code can be.

TMS Vision

I decided to use the knowledge I collected to make an application that works cross-framework and cross-platform to assist people who are visually impaired. The application allowed them to be informed about the environment around them. There were some critical parts in TMS Vision related to the Google Vision and Microsoft Vision APIs that involved uploading the picture taken from the camera. The data required by Google Vision, for example, needed to be in a base64 string. This was handled by the TTMSFNCUtils.FileToBase64 function included in TMS FNC Core. Below you can see a code snippet that uses this functionality to upload the picture data to Google Vision.

procedure TTMSFNCCustomCloudGoogleVision.AnalysePicture(const AFile: TTMSFNCUtilsFile);
var
 basestring :String;
begin
  try
    basestring := TTMSFNCUtils.FileToBase64(AFile);
    Request.Clear;
    Request.Host := Service.BaseURL;
    Request.Path := '/v1/images:annotate';
    Request.Method := rmPOST;
    Request.AddHeader('Content-Type','application/json; charset=utf-8');
    Request.Query := 'key='+Authentication.Key;
    Request.PostData := '{"requests": [{"image": {"content":"'+      
    basestring+'"}'+',"features": [{"type": "LABEL_DETECTION"},{"type":    
    "OBJECT_LOCALIZATION","maxResults": 5},{"type": "WEB_DETECTION"}]}]}' ;
    ExecuteRequest({$IFDEF LCLWEBLIB}@{$ENDIF}DoRequestAnalyse);
  finally
  end;
end;

Example of how the application looks now. The layout of the app has been created with the TMS FNC UI Pack, and runs on TMS WEB Core. The application is a PWA that is installable on the device.



CONCLUSION

Right now I'm in my second half of my internship and can say I enjoyed every moment of it, gaining access to the tools of TMSSoftware and the wide variety of FNC components, made programming in Delphi or Pascal a lot easier than I thought.

I’m still expanding my knowledge of Delphi and Object Pascal and I plan to expand the TMS Vision application with other API services such as Google speech to text to remove the need to interact with the screen manually by implementing voice commands.


Author: Brutin Bjorn

Masiha Zemarai


Bookmarks: 

This blog post has received 4 comments. Add a comment.



Video: Adding user-interaction with drill-down/detail content from a database to a Google Chart web application (3/3)

Bookmarks:  The video series has taught us how to build a custom web service to deliver data to the web application showing a Google Chart. Displaying information is wonderful, but the chart shows only aggregated values. Any user of the application will have the desire to drill down into the data and not just see the sums and averages.

That is why this video will show you how to add user-interaction and query the database to show specific information:

You will learn how to:
  • Add interaction to your chart
  • Add a pop-up window that displays drill-down information, also requested from the web service
  • Specify XData Query operations

Here is a link to the video:



Holger Flick


Bookmarks: 

This blog post has not received any comments yet. Add a comment.



Video: Developing a web application with Google Charts (2/3)

Bookmarks: 

Thursday, May 02, 2019

After having created the service to retrieve the statistical information from the database and prepare it for our web application, we can develop the web application.

We will, of course, use TMS Web Core to develop the web application quickly and efficently. As we use a web service that is created with XData we can rely on the XData controls that are offered for TMS Web Core to develop using the RAD principle.

In detail, you will learn how to:

  • Create a new TMS Web Core application
  • Use non-visual data components to connect to XData
  • Use Google Maps component in a web application



Holger Flick


Bookmarks: 

This blog post has not received any comments yet. Add a comment.




Most Recent Post  |  Next Post  |  Previous Post  |  Index List