This unit provides a static class for reading and modifying the environment variables available to the current process, along with a class that can be used to enumerate environment variable names.
The unit also contains a component and a set of routines that duplicate some of the features provided by the static class. These are now deprecated and are provided for backward compatibility reasons only: they should no longer be used in new code and may be removed in a future version.
More information is available on the Environment Variables Unit Home Page.
The Environment Variables Unit has been tested on all Delphi versions from 7 to XE4, excluding Delphi 2005. The unit is thought to be compilable with versions of Delphi back to version 4, but this has not been tested.
The unit is compatible with both the Windows 32- and 64-bit Delphi compilers and the VCL and FireMonkey frameworks (tested with FireMonkey 2 only).
.NET and non-Windows platforms are not supported.
The Environment Variables Unit and documentation are supplied in a zip file. Before installing you need to extract all the files from the zip file. The following files will be extracted:
PJEnvVars.pas
– The Environment Variables Unit. Contains all source code, including the deprecated component, but excluding the component registration code.PJEnvVars.dcr
– Component palette glyph for the deprecated component.PJEnvVarsDsgn.pas
– Registration code for the deprecated component.README.md
– This read-me file.CHANGELOG.md
– The project change log.MPL-2.txt
– The Mozilla Public License v2.0.Documentation.url
– Short-cut to the unit's online documentation.In addition to the above files you will find the source code for various demo projects in the Demos
directory.
There are four possible ways to use the unit:
PJEnvVas.pas
to your projects whenever the unit is needed.PJEnvVars.pas
to a Delphi package.ddablib/envvars
GitHub repository as a Git submodule and add it to your project. Obviously, it's safer if you fork the repo and use your copy, just in case ddablib/envvars
ever goes away.NOTE: None of the above methods will install the deprecated component into the Delphi IDE. To do this you need to add
PJEnvVars.pas
,PJEnvVars.dcr
andPJEnvVarsDsgn.pas
to a design time package. If you need help doing this see here. This is not recommended other than for reasons of backwards compatibility.
The Environment Variables Unit has comprehensive online documentation.
In addition there is an article, How to access environment variables, that discusses interaction with environment variables on Windows.
Two different demo programs are included in the Demos\1
and Demos\2
sub-directories. There are VCL and FireMonkey 2 versions of each demo.
The demo programs are documented in the README.md
file in the Demos
directory.
A complete change log is provided in CHANGELOG.md
that is included in the download.
The Environment Variables Unit is released under the terms of the Mozilla Public License v2.0.
Bugs can be reported or new features requested via the project's Issue Tracker. A GitHub account is required.
Please check if an issue has already been created for a similar report or request. If so then please add a comment containing as much information as you can to the existing issue, or if you've nothing to add, just add a :+1: (:+1:
) comment. If there is no suitable existing issue then please add a new issue and give as much information as possible.
I'm Peter Johnson – a hobbyist programmer living in Ceredigion in West Wales, UK, writing mainly in Delphi. My programs and other library code are available from: https://delphidabbler.com/.
This document is copyright © 2008-2022, P D Johnson.