Environment Variables Unit

   
Release: 2.0
Date: 23 October 2010
Delphi Compatibility:
 D1   D2   D3   D4   D5   D6   D7  D2005 D2006 D2007 D2009 D2010  DXE  DXE2
Red LED Red LED Red LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Grey LED Grey 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.
  • Routines that get details of all environment variable names and 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.
  • A routine that gets the size of the current environment block.

Documentation

The unit is documented in the Environment Variables Unit Wiki.

Users of Delphi versions 4 to 7 can also make use of the help file that is included in the download. It integrates with the Delphi 4-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.

The help file is no longer being fully updated. The wiki is now the primary documentation source.

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 some of 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.