[fpc-pascal] environmentstrings in windows

Michael Van Canneyt michael.vancanneyt at wisa.be
Thu Dec 14 16:52:09 CET 2006



On Thu, 14 Dec 2006, Vincent Snijders wrote:

> Consider the following program:
> 
> {$mode objfpc}{$H+}
> 
> uses
>   SysUtils;
> 
> var
>   i: integer;
>   s: string;
> 
> begin
>   i := GetEnvironmentVariableCount;
>   writeln('VariableCount: ',i);
>   s := GetEnvironmentString(1);
>   writeln('Variable 1: ', s);
>   s := GetEnvironmentString(2);
>   writeln('Variable 2: ', s);
>   s := GetEnvironmentVariable('=D:');
>   writeln('Variable 1: ', s);
> end.
> 
> If I run this from a command prompt on my windows 2000 computer it gives the
> following output:
> VariableCount: 43
> Variable 1: =D:=D:\lazarus\bugs\7699
> Variable 2: =ExitCode=00000000
> Variable 1:
> 
> The first two envrionment string are special, in the sense that their name
> start with a =.
> 
> but if ask for the value of the environment variable '=D:', it returns the
> empty string.
> 
> I am wrestling a bit with how to interprete this. Should I consider these
> variable as special and hidden and ignore them?
> Or should code parsing environmentstrings be able to handle variables with a
> '=' on the first position?

IMHO, you should not be allowed to have a = in the name of an environment
variable at all. Since obviously you can in Windows, this is a problem which
will need fixing somehow. 
I'm pretty sure you can't do this in Linux (I get an illegal variable name error).
So code relying on this will not be cross-platform.

Michael.



More information about the fpc-pascal mailing list