5-Minute-Snack: Determine the operating system your app is running on

Sometimes, we cannot just rely on the framework, we need to make direct calls to the operating system. Too bad, there is not a single call for every operating system. Without knowing which environment is running in, it is hard to make the right decision. Back in the day, we needed to juggle around pCHARs, buffers and all sorts of data structures in order to determine the operating system in Delphi. Since XE2 it has become much easier as a class called TOSVersion delivers all we need. However, a lot of Delphi developers are unaware of this wonderful helper class which is a part of System.SysUtils:

 

You can see right away that this class is exactly what we have been looking for! Not only can we determine the version and its architectur but also the operating system. That means you can use this function in the VCL and FireMonkey just the same.

I have to emphasize that the class overwrites ToString. In order to provide your users with a nice and readable info string about the operating system, simply use TOSVersion.ToString. Mind, that you do not have to instantiate the class as an object. Use the classname as all properties and functions are defined for the class.

Finally, there is no need to compare version numbers in your code. Use the Check functions that are provided to check for certain version numbers etc.

Tags: , , , , , ,

5-Minute-Snack: Determine the vertical refresh rate in Hz of your display

Delphi has taken great strides in the RTL that make using direct Windows API calls more and more redundant. A lot of things can be determined using classes that can either be found in the RTL or VCL. However, the vertical refresh rate seems to have been overlooked as I cannot find it in any of the new classes of the RTL. Neither TScreen nor TMonitor deliver a solution.

First, the solution I provide will be valid for Windows 2000 upwards. Another 5-Minute-Snack will focus on how to get information about your operating system version using TOSVersion. I doubt that anyone still will have to check for versions older than that but better safe than sorry.

Next, you need to know that the Windows API function GetDeviceCaps can be used to retrieve information about a drawing context (DC). In the VCL, you get the DC using the Handle of the Canvas of the window: self.Canvas.Handle. The function also requires a second parameter to determine what kind of information you would like to know. Further, it always will return an integer. Sometimes, you need to refer to the documentation what this integer means. In this case, however, the integer determines the vertical refresh rate. We just need to know the constant for it. In order to request the vertical refresh rate, we can use the constant VREFRESH.

If we place a button and an edit field on a form, we can implement the OnClick-event of the button as follows:

 

This way, the edit field will contain the refresh rate after clicking the button:

Tags: , , , , , , , ,

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

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:

There is no need to do anything else with LStream.

Tags: , , , , , , , , ,

Video: Google Maps with Style

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
Tags: , , , , , , ,

Partnerships



Top