Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing Environment Variables from Delphi 1.0

3 views
Skip to first unread message

Duncan Groenewald

unread,
Jun 11, 1997, 3:00:00 AM6/11/97
to

How do I access environment variables (PATH, etc) from Delphi 1.0
running under Windows 3.1 ?

The equivalent C function would be getenv().

--
*************************************
Duncan A. Groenewald [IVS]
dun...@iafrica.com
*************************************

Kirk B. Spadt

unread,
Jun 13, 1997, 3:00:00 AM6/13/97
to

In article <339F1C...@iafrica.com>,

Duncan Groenewald <dun...@iafrica.com> wrote:
>How do I access environment variables (PATH, etc) from Delphi 1.0
>running under Windows 3.1 ?
>
>The equivalent C function would be getenv().


Here's my GetEnv:

function GetEnv(const Name: String; const Default: String): String;
var
Tag: array[0..64] of Char;
TagLen: Integer;
p1: PChar;
PosEqual: PChar;
begin
Result := Default;
StrPCopy(Tag, Name);
TagLen := Length(Name);
p1 := GetDOSEnvironment;
while p1^ > #0 do begin
PosEqual := StrPos(p1, '=');
if PosEqual <> Nil then begin
if StrLIComp(p1, Tag, TagLen) = 0 then begin
Result := StrPas(PosEqual + 1);
break;
end;
end;
Inc(p1, StrLen(p1) + 1);
end;
end;

Usage:

ThePath := GetEnv('PATH', 'C:\windows');

will retrieve the DOS environment assigned to PATH or return the default in
the second param if the first param is not an environment variable. First
param is case-insensitive.

For D2, I think you use GetEnvironmentVariable.

-Kirk

------------------------------------------------
Kirk B. Spadt ksp...@keyware.com
Keyware Systems, Inc.
570 Lindsey Drive (610) 964-9530
Radnor, PA 19087 (610) 964-0543 fax

0 new messages