Blog Options
Archive
<< April 2024 >>-
Monday 22
- Easy Guide to Building a Pexels Gallery App with TMS WEB Core -
Wednesday 17
- New free component for sophisticated file uploads with TMS WEB Core -
Tuesday 16
- Closing the gap with TMS FNC UI Pack new additions -
Thursday 11
- Unveiling the Latest Enhancements in TMS VCL UI Pack -
Friday 5
- TMS components and Delphi and C++Builder 12.1 -
Wednesday 3
- Customizing the login page of your application using TMS Sphinx
- A Python library for using StellarDS.io effortlessly
- Introducing: How it Works with Holger - Building a Pexels gallery app with TMS WEB Core video series
- TMS FNC Cloud Pack with StellarDS.io backend: unparalleled productivity in VCL & FMX
Authors
- Bernard Roussely (1)
- Wagner Landgraf (82)
- Roman Yankovsky (2)
- Bart Holvoet (27)
- Aaron Decramer (18)
- Pieter Scheldeman (99)
- Nancy Lescouhier (32)
- Adrian Gallero (33)
- Bruno Fierens (403)
- Marcos Douglas B. Santos (5)
- Wagner R. Landgraf (1)
- Bradley Velghe (16)
- Bernard (2)
- Andrew Simard (86)
- Holger Flick (15)
- Gjalt Vanhouwaert (30)
- Tunde Keller (22)
- Masiha Zemarai (119)
Blog
All Blog Posts | Next Post | Previous PostFNC Code Gems: Helpers for Base64 encoding and decoding
Bookmarks: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
Bookmarks:
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post