Skip to content

System.Environment (en)

Alex edited this page Nov 14, 2019 · 1 revision

Provides information about, and means to manipulate, the current environment. This class cannot be inherited.

TEnvironment = class sealed

Examples

The following code example demonstrates displays a list of information about the current environment.

procedure PrintEnvironmentVariables;
var
  EnvVariables: IDictionary<string, string>;
  variable: TPair<string, string>;
begin
  Writeln('Print all environment variables...');

  EnvVariables := TEnvironment.GetEnvironmentVariables;

  Writeln('Environment Variables:');
  for variable in EnvVariables do
     Writeln(variable.Key + ' = ' + variable.Value);

  Writeln('');
end;

procedure PrintEnvironmentVariable(Key: string);
var
  value: string;
begin
   Writeln('Print single environment variable...');
   value := TEnvironment.GetEnvironmentVariable(key);
   Writeln(Key + ' = ' + value);
end;

procedure SetEnvironmentVariable(key, value: string);
begin
  Writeln('Set environment variable...');
  TEnvironment.SetEnvironmentVariable(key, value);

  Writeln('Check new variable value...');

  PrintEnvironmentVariable(key);

  Writeln('Cleanup variable value');
  TEnvironment.SetEnvironmentVariable(key, value);
end;

Clone this wiki locally