Blog Options
Archive
<< December 2025 >>-
Monday 15
- Use Your Own Controls in the FNC Filter View -
Thursday 11
- TMS Training Days 2026 -
Tuesday 9
- Next Generation Data Grid for Delphi: Excel Style Selection -
Thursday 4
- Ho Ho Ho! Our TMS Advent Calendar is Coming! -
Wednesday 3
- Next Generation Data Grid for Delphi: Cell Classes -
Tuesday 2
- A New Way of Flexible Filtering with TTMSFNCFilterView
Authors
- Bernard Roussely (3)
- Wagner Landgraf (93)
- Dennis Röhner (1)
- Roman Yankovsky (2)
- Bart Holvoet (41)
- Aaron Decramer (63)
- Pieter Scheldeman (127)
- Nancy Lescouhier (32)
- Adrian Gallero (34)
- Bruno Fierens (446)
- Marcos Douglas B. Santos (5)
- Bernard (4)
- Bradley Velghe (35)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (44)
- Tunde Keller (33)
- 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