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

Getting value of environment variable from delphi, value of PATH

50 views
Skip to first unread message

Knut Erik Terjesen

unread,
Jan 4, 1996, 3:00:00 AM1/4/96
to
In an Delphi application I would like to get the value of my
environment variable, in this case the value of my PATH variable.
Are there any functions in Delphi I can use.

Thanks in advance


Marcus Chapman

unread,
Jan 4, 1996, 3:00:00 AM1/4/96
to knut.t...@sybase.no
Use the GetEnvVar() function, located in the WinDOS library.

Marcus Chapman
------------------------------------------------
The information I post is wholly my own, and not
necessarily the view of my employer.
------------------------------------------------

John DeValk

unread,
Jan 5, 1996, 3:00:00 AM1/5/96
to
Marcus Chapman <mcha...@mstarlabs.com> writes

What is the WinDOS library and where do I get it?

John

-The opinions expressed here do not reflect those of my employer.
-Check out a Poi Dog Pondering on The Sea and Cake.

Christian Tiberg

unread,
Jan 6, 1996, 3:00:00 AM1/6/96
to
Marcus Chapman wrote in a message to All:

MC> Use the GetEnvVar() function, located in the WinDOS library.

I've thought about wrapping this up in a class called TDosStuff, with a
property named Environment that calls the above function implicitly .... Never
had the time though... Should also include properties named Temp, Path and so
on, that calls Environment['PATH'] and so on..

Best regards,
Christian // cti...@silver.ct.se
// CServe 100777,2775

... Celery raw develops a jaw. But stewed, is quietly chewed


Kirk Wolak

unread,
Jan 7, 1996, 3:00:00 AM1/7/96
to
Look in the Delphi Knowledge Base, code is included!
You can find it at
http"//www.teleport/com/~grump/delphi.htm

HTH,
Kirk


In article <1996Jan5.1...@il.us.swissbank.com>,
dev...@il.us.swissbank.com says...
>
>Marcus Chapman <mcha...@mstarlabs.com> writes


>> Use the GetEnvVar() function, located in the WinDOS library.
>>

Raize 95

unread,
Jan 8, 1996, 3:00:00 AM1/8/96
to
>> Use the GetEnvVar() function, located in the WinDOS library.<<<

You'll run into problems using the WinDos unit if you do any date or time
processing. The problem occurs because the WinDos unit is a carry over
from BP7 and the TDateTime type was defined in that unit. In Delphi,
TDateTime is defined in the System unit and more importantly is a
different type.

A better approach is to use the following function which does not rely on
WinDos and uses Pascal (i.e. Delphi) strings rather than PChars.

Later,
Ray
---------------------
unit DlphiDos;

interface

function GetEnvStr( VarName : string ) : string;

implementation

uses
WinProcs, SysUtils;

{=============================================================}
{= GetEnvStr - Get Dos Environment Variable Setting =}
{= =}
{= This function is a modified version of the GetEnvVar =}
{= function that appears in the WinDos unit that comes =}
{= with Delphi. This function's interface uses Pascal =}
{= strings instead of null-terminated strings. =}
{=============================================================}

function GetEnvStr( VarName : string ) : string;
var
Len : Word;
EnvStz : PChar;
NameStz : array[ 0..180 ] of Char;
begin
StrPCopy( NameStz, VarName ); { Covert VarName to PChar }
Len := StrLen( NameStz );
EnvStz := GetDosEnvironment; { EnvStz holds entire env }

while EnvStz^ <> #0 do
begin { Pick off Variable Name and Compare }
if ( StrLIComp( EnvStz, NameStz, Len ) = 0 ) and
( EnvStz[ Len ] = '=' ) then
begin { Convert to Pascal string before returing }
Result := StrPas( EnvStz + Len + 1 );
Exit;
end;
Inc( EnvStz, StrLen( EnvStz ) + 1 ); { Jump to Next Var }
end;
Result := '';
end;

end.


Marcus Chapman

unread,
Jan 8, 1996, 3:00:00 AM1/8/96
to dev...@il.us.swissbank.com
dev...@il.us.swissbank.com (John DeValk) wrote:
>Marcus Chapman <mcha...@mstarlabs.com> writes

>> Use the GetEnvVar() function, located in the WinDOS library.
>>
>> Marcus Chapman
>> ------------------------------------------------
>> The information I post is wholly my own, and not
>> necessarily the view of my employer.
>> ------------------------------------------------
>>
>> knut.t...@sybase.no (Knut Erik Terjesen) wrote:
>> >In an Delphi application I would like to get the value of my
>> >environment variable, in this case the value of my PATH variable.
>> >Are there any functions in Delphi I can use.
>> >
>> >Thanks in advance
>> >
>>
>
>What is the WinDOS library and where do I get it?
>
>John
>
>-The opinions expressed here do not reflect those of my employer.
>-Check out a Poi Dog Pondering on The Sea and Cake.

John,
I found the WinDOS library in my Delphi10\Source directory (where it is
in your, I can't be sure). I'm fairly sure that it comes with Delphi,
but I didn't install our copy. Check around your source directories.
(the actual .PAS file is located in my \Source\RTL70 directory).

Marcus


Kirk Wolak

unread,
Jan 9, 1996, 3:00:00 AM1/9/96
to
Check out the Delphi Knowledge Base, sample code and everything!
Address at in my signature!

HTH,
Kirk

In article <4cro99$o...@news.halcyon.com>, mcha...@mstarlabs.com says...

--
___________________________________________________________________________
Kirk Wolak
KWo...@mail.cbf.com
//
// Const ViewsExpressed = "My own and not those of the company I work for!";
//
Look at the Delphi Knowledge Base for answers to your questions...
http://www.teleport.com/~grump/delphi.htm


Tibor F. Liska

unread,
Jan 10, 1996, 3:00:00 AM1/10/96
to
In article <1996Jan5.1...@il.us.swissbank.com> dev...@il.us.swissbank.com (John DeValk) writes:
>From: dev...@il.us.swissbank.com (John DeValk)
>Subject: Re: Getting value of environment variable from delphi, value of PATH
>Date: Fri, 5 Jan 1996 17:06:07 GMT

>Marcus Chapman <mcha...@mstarlabs.com> writes
>> Use the GetEnvVar() function, located in the WinDOS library.
>>
>> Marcus Chapman
>> ------------------------------------------------
>> The information I post is wholly my own, and not
>> necessarily the view of my employer.
>> ------------------------------------------------
>>
>> knut.t...@sybase.no (Knut Erik Terjesen) wrote:
>> >In an Delphi application I would like to get the value of my
>> >environment variable, in this case the value of my PATH variable.
>> >Are there any functions in Delphi I can use.
>> >
>> >Thanks in advance
>> >
>>

>What is the WinDOS library and where do I get it?

>John

>-The opinions expressed here do not reflect those of my employer.
>-Check out a Poi Dog Pondering on The Sea and Cake.

This is the GetEnvVar from WinDos:

function GetEnvVar(VarName: PChar): PChar;
var
L: Word;
P: PChar;
begin
L := StrLen(VarName);
P := GetDosEnvironment;
while P^ <> #0 do
begin
if (StrLIComp(P, VarName, L) = 0) and (P[L] = '=') then
begin
GetEnvVar := P + L + 1;
Exit;
end;
Inc(P, StrLen(P) + 1);
end;
GetEnvVar := nil;
end;

Use like this:

var DosPath : string;
...
DosPath := StrPas(GetEnvVar('PATH'));


Tibor Liska


0 new messages