Delphi using Environment Variables in your App
Environment Variables can help you extract data that require some in-depth coding to achieve the same result. So here is a simple way to replace lengthy legacy code or create some new code with
function GetEnvironmentVariable(const Name: string): string; found in the System.SysUtils library.
What it is?
The ‘GetEnvironmentVariable’ method is a way to retrieve the value of an environment variable passed as a string (name) for the current process using a standard list of Windows based variables that can be extracted.
How useful is it?
These Environment Variables are a standard across all OS’s and for different processors thereby ensuring that there is no requirements for ‘IFDEFs’.
I found it useful to extract :-
Downloadt the simple App that calls each Environment Variable via a combobox that shows the result real time on your Windows machine. Perhaps there are a few other options that you could find useful.
Here is the list of the Standard Environment Variables.
ALLUSERSPROFILE - Generic user profile.
APPDATA - Path of the application data folder.
CLIENTNAME - Name of Client machine.
COMMONPROGRAMFILES - Path of common program files folder.
COMPUTERNAME - Name of Computer code is running on.
COMSPEC - Path of the cmd.exe program.
HOMEDRIVE - Current home drive designation, such as 'C:'
HOMEPATH - Path to current location for document storage.
LOGONSERVER - Specifies a domain controller for user logon authentication.
NUMBER_OF_PROCESSORS - Number of processors on current machine.
OS - Base name of the Operating System.
PATH - The current program path.
PATHEXT - Extension types of executable files.
PROCESSOR_ARCHITECTURE - Type of CPU architecture. For example, X86 for Intel Pentium processors.
PROCESSOR_IDENTIFIER - ID number of current machine.
PROCESSOR_LEVEL - More detailed description of the CPU architecture.
PROCESSOR_REVISION - Processor revision level.
PROGRAMFILES - Path of the program files folder.
SESSIONNAME - Name of the current OS session.
SYSTEMDRIVE - Drive the OS operates from.
SYSTEMROOT - Sets the system directory.
TEMP - Path of the temporary files folder.
TMP - Directory to store temporary files to.
USERDOMAIN - Specifies the domain of the current machine.
USERNAME - Name of the current user.
USERPROFILE - Path of the folder holding the current user's information.
WINDIR - Path of the Windows folder.
Feel Free to download the sample App from here
June 2019Delphi A Professional VCL DBGrid Part Four
May 2019Delphi A Professional VCL DBGrid Part Three
April 2019Delphi A Professional VCL DBGrid Part Two
March 2019Delphi A Professional VCL DBGrid Part One
November 2018Delphi VCL Buttons in DBGrid
October 2018Two Helper Apps for Delphi LibUSB
September 2018Delphi Libusb Library Introduction
August 2018Delphi Object directly to a Json string in a REST Client
July 2018Delphi FMX Leaflet Plotter using OSM Maps
June 2018C2PAS32 Convertor Application
May 2018Delphi PDF Embedded viewer with PDF.js
March 2018Delphi FMX - Changing TCharacter to TCharHelper
January 2018Delphi FMX Dashboard using Chart.JS
December 2017PHP Slim REST Server & Delphi Auth Part 5
November 2017Delphi FMX REST Client App Part 4
October 2017Delphi VCL REST Pricing Client App Part 3
September 2017Delphi REST VCL Client Basic Auth Part 2B
August 2017Delphi REST Client Part 2A
July 2017PHP REST Server and Delphi Client Intro
June 2017Delphi SQLite Encryptor-Decryptor Tool
May 2017Create a Visual IP Address Geolocation with PHP
March 2017PHP Downloader using Countdown timer
January 2017Morris Charts and PHP-PDO
December 2016CSS to create a functional Toggle Button