Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

SetValue class method

Project: Environment Variables Unit

Unit: PJEnvVars

Class: TPJEnvironmentVars

Applies to: ~>3.0

class function SetValue(const VarName, VarValue: string): Integer;


Sets the value of a given environment variable for the current process. If the environment variable does not exist then it is created.



The most likely causes of error are attempting to set the value of an un-named environment variable or when the environment block is full and there is no room for the new value or to create a new variable. A description of any error can be found by passing the error code to SysErrorMessage from the SysUtils or System.SysUtils unit.

Important: Setting an environment variable to the empty string does not delete it from the environment block: use the Delete method to do that.

Note: This method does not update the system’s environment variables, only the copy of the environment maintained by this program. Changes are lost when the program terminates.