Главная страница | назад





Article #17889: Reading dos environment variables

 Question and Answer Database
FAQ2889D.txt Reading dos environment variables
Category :Windows API
Platform :All
Product :All 32 bit
Question:
How do I retrieve a DOS environment variable such as the current
path?
Answer:
You can make a call to the Windows API function
GetDOSEnvironment() under Win16 or the
GetEnvironmentStrings() function under Win32.
Example:
procedure TForm1.Button1Click(Sender: TObject);
var
p : pChar;
begin
Memo1.Lines.Clear;
Memo1.WordWrap := false;
{$IFDEF WIN32}
p := GetEnvironmentStrings;
{$ELSE}
p := GetDOSEnvironment;
{$ENDIF}
while p^ <> #0 do begin
Memo1.Lines.Add(StrPas(p));
inc(p, lStrLen(p) + 1);
end;
{$IFDEF WIN32}
FreeEnvironmentStrings(p);
{$ENDIF}
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99