Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.85 KB

TPJEnvVarsEnumerator.md

File metadata and controls

47 lines (34 loc) · 1.85 KB

TPJEnvVarsEnumerator class

Project: Environment Variables Unit

Unit: PJEnvVars

Applies to: ~>3.0

Description

Implements an enumerator for the names of all environment variable names in the current process.

Note: This class was originally provided to work with the deprecated TPJEnvVars component's GetEnumerator method to enable TPJEnvVars instances to be enumerated in for..in statements when compiled with Delphi 2005 or later. The class can also be used directly from code.

Important: Environments variables should not be modified while the enumerator is being used. Any addition or deletion of environment variables will not be reflected in the enumeration. Making such changes can result in obscure bugs.

Methods

Method Description
Create Constructs and initialises a new enumeration object instance.
GetCurrent Returns the name of the current environment variable in the enumeration. Can be used interchangeably with the Count property.
MoveNext Moves to the next name in the enumeration if it exists. Returns True if it was possible to move to the next item or False if there are no more items in the enumeration.

Properties

Property Description
Current Records the name of the current environment variable in the enumeration. Can be used interchangeably with the GetCount method.

Example

This is an example of using TPJEnvVarsEnumerator directly from code. The code writes the names of every environment variable to the console.

var
  Enum: TPJEnvVarsEnumerator;
begin
  Enum := TPJEnvVarsEnumerator.Create;
  try
    while Enum.MoveNext do
      WriteLn(Enum.Current);
  finally
    Enum.Free;
  end;
end;