Environment Variables Unit

   
Release: 1.3.1
Date: 20 February 2010
Delphi Compatibility:
 D1   D2   D3   D4   D5   D6   D7  D2005
(Win32)
D2006
(Win32)
D2007 D2009
(Win32)
D2010
(Win32)
Red LED Red LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED

About the Unit

Introduction

This unit provides a component and various routines for manipulating environment variables. Features include:

  • A component that can enumerate all the environment variables, can get and set values and can delete variables.
  • A set of routines that effectively duplicate the functionality of the component.
  • A routine that can store details of all environment variables in a string list (as Name=Value pairs).
  • A routine that can replace environment variable references in strings (of the form %ENVVAR%) with the variable's value.
  • A routine to create a customised environment block for passing to child processes.

Documentation

The unit is documented in the Environment Variables Unit Wiki.

Users of Delphi versions 3 to 7 can also make use of the help file that is included in the download. It integrates with the Delphi 3-7 help system. The help file is a WinHelp file and therefore does not work on Windows Vista unless WinHelp has been downloaded and installed. See Microsoft Knowledge Base Article KB917607 for further information.

Demo Code

A file named DemoCode.htm is provided in the download that presents worked examples of using the component and the various routines.

Source code of several projects that implement the examples in DemoCode.htm are available in this repository.

How it works

This unit uses ideas from my article "How to access environment variables". The article shows how to develop routines similar to those in this unit and discusses their operation.

Feedback

If you find any bugs or want to suggest a new feature please report them using the Issue Tracker. Be sure to tag any issues as Project-envvars. If you have created a bug fix or have implemented a new feature please attach a zip file or diff containing your source code.

Please Note
It is a common mistake to believe that you can change Windows environment variables by altering them from your program using SetEnvironmentVariable. You can't. The section " A little background information" in the article noted above explains.
Please don't report this issue as a bug.

If you have any other comments please contact me.