Blog

All Blog Posts  |  Next Post  |  Previous Post

FNC Code Gems: Display information and common folders

Tuesday, July 16, 2019



The FNC framework helps you to develop framework-independent, cross-platform applications. It has been conceived by tmssoftware.com a couple of years ago and has recently added the web as one of its platforms fascilitating TMS Web Core.

FNC really helps you to use the same source code for Windows, MacOS, iOS, Android, Linux and Raspberry Pi. Further, you can use the same components in the frameworks that give you access to these platforms: VCL, FMX and LCL.

A lot of functionality is exposed using non-visual components as well. However, I recently found a true gem of a class in its TMSFNCUtils.pas unit. The unit, of course, is available as VCL.TMSFNCUtils.pas, FMX.TMSFNCUtils.pas, and LCL.TMSFNCUtils.pas which means it can be used in any framework.

The unit contains one significant class called TTMSFNCUtils that offers a plethora of functionality that is usually tedious to implement and repetitive.

Today, we will focus on two different aspects in this blog post, and I will post more functionality in the coming weeks.

Display attributes

As blogged a couple of days ago, getting information about your display is very important so that you can scale your images correctly.TTMSFNCUtils gives you two very useful methods to get the relevant information about your forms and components quickly. Knowing what DPI your display uses is only half the work as you also need to know what DPI a certain component was designed for:

type
 TTMSFNCUtils = class
  public  
    class function IsHighDPIScale: Boolean;
    class function GetDPIScale({%H-}AOwner: TComponent = nil): Single;
 end;

Be aware, that all methods are class-methods, i.e. you can determine if the current form uses a High DPI scale using:

LIsHighDPI := TTMSFNCUtils.IsHighDPIScale;

GetDPIScale allows you to specify a component or a form. If you specify nil the DPI scale of the form will be returned.

Getting common folders

Any application I have built so far needed to know the user’s documents directory and the application directory. The utility class provides cross-platform helper methods for both:

type
 TTMSFNCUtils = class
  public
 
    class function GetDocumentsPath: String;
    class function GetAppPath: String;
 end;

Getting the user’s document directory and the application directory now becomes two lines of code for all supported platforms:

LMyDocPath := TTMSFNCUtils.GetDocumentsPath;
 LAppPath   := TTMSFNCUtils.GetAppPath;

Providing flexible classes as TTMSFNCUtils, the framework truly takes away the chores of multi-framework-multi-platform development.



Holger Flick




This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post