Thanks in advance
Marcus Chapman
------------------------------------------------
The information I post is wholly my own, and not
necessarily the view of my employer.
------------------------------------------------
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.
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
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.
>>
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.
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
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
>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