[fpc-pascal] SysUtils.GetEnvironmentVariable

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Thu Mar 29 13:17:01 CEST 2012



On Thu, 29 Mar 2012, Marcos Douglas wrote:

> On Thu, Mar 29, 2012 at 5:42 AM, Mark Morgan Lloyd
> <markMLl.fpc-pascal at telemetry.co.uk> wrote:
>> Marcos Douglas wrote:
>>
>>> I know that I have to define the environment variable before or after
>>> starting the application or IDE.
>>> As I said, works in WinXP... but I had a little problem with a client
>>> using Win7 so, I talked about this on lazarus-br list and asked to
>>> somebody do the test on Win7 and they said the test did not work so, I
>>> wrote here.
>>
>>
>> I think the absolutely crucial thing here is to ask what the relationship
>> between the session in which the shell/environment variable was defined, and
>> the FPC program.
>
> Nothing.
>
>> If the variable is set and the program is run from the same prompt, provided
>> that it's not messed up by extra spaces or by e.g. an interposed
>> command.com, then it should work.
>
> No. The variable is set using a install program or Windows.
>
>> In any other case it might work, and it's entirely reasonable to assume that
>> the extent to which variables are passed between running processes will vary
>> wildly with OS version.
>>
>> I suggest the *first* thing to do is to confirm that the variable has stuck
>> by using the  set  command. After that try running the Pascal program.
>
> No command set is used.
> The variable has been created in the Windows System Variables.

He means that you must check using the SET command in a command window.

So run - execute : CMD.exe

In the command terminal that opens, type 'SET' (+enter)

Your variable should show up in the list of environment variables.

Please note that under windows 7, there are system environment variables, 
and user variables.

If the application is installed using user A, but user B runs your program,
it is possible that the environment variable is not shown.

It depends on how the variable was created by your installer. To check this,
the command window can be used.

The RTL of Free Pascal just calls the Windows API to get the environment variable. 
No magic is performed.

Michael.


More information about the fpc-pascal mailing list