Blog Options
Archive
<< June 2025 >>-
Friday 27
- Top 3 Most-Read TMS Software Blog Posts June 2025 -
Thursday 26
- A Long-Awaited Upgrade for Context Menus in Delphi -
Wednesday 25
- Installing AWS SDK for Delphi with Smart Setup -
Tuesday 24
- TMS FNC Data Grid Essentials: Videos & Blogs -
Thursday 12
- TMS Smart Setup is now Open Source! -
Thursday 5
- Meet the New Doctor in TMS Smart Setup -
Wednesday 4
- Using TMS MQTT Capabilities to Send Data in an Embarcadero Delphi FMX App -
Monday 2
- Add AI superpower to your Delphi & C++Builder apps part 6: RAG
Authors
- Bernard Roussely (1)
- Wagner Landgraf (91)
- Roman Yankovsky (2)
- Bart Holvoet (40)
- Aaron Decramer (46)
- Pieter Scheldeman (122)
- Nancy Lescouhier (32)
- Adrian Gallero (33)
- Bruno Fierens (436)
- Marcos Douglas B. Santos (5)
- Wagner R. Landgraf (1)
- Bradley Velghe (31)
- Bernard (3)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (41)
- Tunde Keller (29)
- Masiha Zemarai (117)
Blog
All Blog Posts | Next Post | Previous Post
FNC Code Gems: Helpers for Base64 encoding and decoding
Friday, July 19, 2019

In the last post, I looked at methods to help you get information about connected displays and determine the path name for common folders. Lets look at something very valuable when you want to convert binary data into a string: Base64 encoding.This is somewhat tricky if you have to consider all the different platforms and frameworks. FNC makes it very easy!
Again, the class TTMSFNCUtils offers awesome methods to get results quickly:
class function FileToBase64(const AFile: TTMSFNCUtilsFile): string; class function Decode64(const AValue: string; const AURL: Boolean = False): string; class function Encode64(const AValue: string; const AURL: Boolean = False): string; overload; class function Encode64(const AValue: TBytes; const AURL: Boolean = False): string; overload;
Not only are there methods to encode and decode strings, there is also FileToBase64 which allows you to retrieve the Base64 string for a file using a single line of code:
LBase64String := TTMSFNCUtils.FileToBase64( 'mydata.bin' );
Ignore the data type of AFile to specify the filename. In VCL and FMX the type TTMSFNCUtilsFile it is mapped to a string. However, for web applications you cannot specify a local file name and the method has to be invoked differently. There is no inverse function for this as it is already a one-liner in Delphi now to store a string or a byte array into a file using TFile from System.IOUtils.
In order to encode a string, call Encode64; call Decode64 to decode a string:
LMyBase64String := TTMSFNCUtils.Encode64( 'testtest', false ); LMyTestString := TTMSFNCUtils.Decode64( LMyBase64String, false );
Remember, these methods are available for VCL, FMX, LCL, and TMS Web Core.
Holger Flick

This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post