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 from future releases.
Features
The static class has methods to:
-
Read, write and delete environment variables.
-
Query whether an environment variable exists.
-
Get the number of environment variables in the environment block along with the size of the block.
-
List and enumerate the names, or names and values, of all environment variables in the environment block.
-
Create a new environment block suitable for passing to a child process.
There is also an enumerator class the provides an alternative way to enumerate environment variable names.
Demo code
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 file DemosReadMe.htm
that can be found in the Demos
directory.
How the code works
This unit uses ideas from my article "How to access environment variables". The article shows how to develop routines similar to some of the methods in this unit and discusses their operation.