[fpc-pascal] SysUtils.GetEnvironmentVariable

Marcos Douglas md at delfire.net
Fri Mar 30 03:26:55 CEST 2012


On Thu, Mar 29, 2012 at 9:41 PM, Chad Berchek <ad100 at vobarian.com> wrote:
>
> Works fine for me on Windows 7. Here's the Windows version details:
>
> Windows 7 Pro, 64-bit, with Service Pack 1. The "ver" command shows
> 6.1.7601.
>
> I tested 3 cases:
> 1. Setting the environment variable using the "set" command in a command
> line prompt then immediately running the test program.
> 2. Setting a user-specific environment variable in the System control
> panel GUI.
> 3. Setting a machine-wide environment variable in the System control panel
> GUI.
>
> Note: One thing to keep in mind is that programs get their copy of the
> environment when they start. So if you add or change a variable after a
> program has started, that program will likely not see the change until it is
> restarted, and nor would any child processes it starts. For example if you
> open a command line and THEN set an environment variable through another
> program (like the control panel GUI), it will not be visible in that command
> line or any programs you run from it. You'd have to start a new command line
> after you add/change your variable. I believe this has been the way programs
> work since the days of DOS. I.e., they get their copy of the environment
> block when they first start.
>
> For reference here is the test program, compiled with FPC 2.4.2 on Win XP
> Pro 64-bit (as I don't actually have FPC on my Win 7 machine). Here is the
> version output line from the compiler:
>
> Free Pascal Compiler version 2.4.2 [2011/03/08] for i386
>
> and the program:
>
> -----
> program getenvtest;
>
> {$mode objfpc}{$H+}
>
> uses
>  SysUtils;
>
> begin
>  WriteLn(GetEnvironmentVariable('TestVar'));
> end.
> -----

Thanks for the test.
We have a little difference: my FPC is 2.6.1 (svn /fixes_2_6).
The env variable was added before I start the application, always.

Marcos Douglas



More information about the fpc-pascal mailing list