Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Read environment variables
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Windows provides two function to access the operating system's environment strings.
The procedure below reads the environment into a TStringList which you need to pass as a parameter.
An example for a call populating a TMemo field:
GetEnvStringsList(TStringList(Memo1.Lines));
The two relevant API calls are GetEnvironmentStrings and FreeEnvironmentStrings.  | |  | | procedure GetEnvironmentStringsList(EnvironmentStrings: TStringList);
var
PEnv,
PCopyEnv: PChar;
begin
EnvironmentStrings.Clear;
PEnv := GetEnvironmentStrings;
PCopyEnv := PEnv;
if PCopyEnv<>nil then
repeat
EnvironmentStrings.Add(StrPas(PCopyEnv));
Inc(PCopyEnv, StrLen(PCopyEnv) + 1);
until PCopyEnv^=#0;
FreeEnvironmentStrings(PEnv);
PCopyEnv := nil
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|