Link to home
Start Free TrialLog in
Avatar of GOMF
GOMFFlag for Denmark

asked on

Reading an environment variable

Hello folks!

I have VERY embarassing question ;-)

HOW DO I READ AN ENVIRONMENT VARIABLE IN DELPHI ?

Forgive me ;-)


GOMF
Avatar of Madshi
Madshi

Hi GOMF,

use this function...

function GetEnvVar(variable: string) : string;
begin
  SetLength(result,MAX_PATH+1);
  SetLength(result,GetEnvironmentVariable(pchar(variable),pchar(result),MAX_PATH));
end;

Example:   MessageBox(0,pchar(GetEnvVar('path')),'path=',0);

Regards, Madshi.
Avatar of GOMF

ASKER

Dear Madshi,

Problem! I tested your suggestion, which worked. However
if I use Set Test=SOMETHING and run the suggestion with
Test then it doesn't work. Thirdly I wasn't beeing very
precise as to what I needed :-) (sorry)
Actually I need to know a variable from a browser
called HTTP_REFERER which gives me a path which is needed
in an ISAPI extentsion.
I was told that the HTTP_REFERER is an environment variable
however I don't think its is in the extend of what I think
is an environment-variable (me beeing dum ;-) )

GOMF.
Avatar of GOMF

ASKER

Above ;-)

GOMF
Hmmm. The function I gave you, works only for "Set" variables, that are set in dos (before starting windows) or for variables that are set by your own program.
Don't know how you can get other environment variables, if it is that, what you need.
Perhaps you should ask the writer of the browser, how to get this path...

Regards, Madshi.
Avatar of GOMF

ASKER

Madshi,

asking Microsoft about anything isn't exactly a ballgame ;-)
IF I ever receive an answer its probably because they
released an MS Explorer 18.0 ;-) and the version I am using
is utterly outdated ;-)

GOMF
Avatar of GOMF

ASKER

Adjusted points to 250
Hmmm. Looks like a CGI environment variable, right?
I have no experience with CGI programming. Do you have Delphi4? Which CGI component are you using?
In the help for the CGI component that is being shipped with Delphi, there's a property called "environmentStrings", which could help you.

Regards, Madshi.
Avatar of GOMF

ASKER

Madshi,

Well its not CGI, its ISAPI, but I if CGI components hold
environmentstrings, then ISAPI should too - if this
is not something that only exists in Delphi 4.
I use Delphi 3 (unfortunately :-))
I use Tsessions & TPageProducer, and I can't see
they hold any valuable information about the
environment variables.

Best wishes,

GOMF
I've Delphi4, but unfortunately only the professional version, so I don't have any of these CGI/ISAPI/blabla components. And my help file only sais, "object not supported in this Delphi version". So I can't help you further...   :-(

Regards, Madshi.
Hi GOMF,

Saw in the helpfile of the IE 18.0 Beta :O) that your HTTP_Referer is :

"Returns a string containing the URL of the original request when a redirect has occurred."

And indeed its in the Servervariables collection, but I will read on, and will be back on this question.

brUINTje.
And they help us a hand with this one

You can iterate through each server variable name. For example, the following script prints out all of the server variables in a table:

<TABLE BORDER="1">

<TR><TD><B>Server Variable</B></TD><TD><B>Value</B></TD></TR>

<% For Each strKey In Request.ServerVariables %>

<TR><TD> <%= strKey %> </TD><TD> <%= Request.ServerVariables(strKey) %> </TD></TR>

<% Next %>

</TABLE>

I'm absolute no genie in this field so I guess this is some sort of Script piece to be placed in a HTML page.

Hope this helps you any further.
brUINTje
Well, looked at the TPageProducer component and saw in the derived TCustomePageProducer a few methods to retrieve content, contentfromstream and contentformstring, so I guess you have to look in there to retrieve your environment variable.

If you register for the helpfile of MS called MSDN this is the link you have to follow:

http://premium.microsoft.com/isapi/devonly/prodinfo/msdnprod/msdnlib.idc?theURL=/msdn/library/sdkdoc/iisref/vbob5vsj.htm

Hope this helps
:O)
brUINTje.
Hi GOMF,

Think it's a piece of script to be placed into a ASP page, as I said I'm no expert in this field, but maybe I willl look into it further if the need may arise..

:O)
brUINTje.
Avatar of GOMF

ASKER

bruintje,

Well then, we are getting closer ;-) Yes these are the
variables I need! And thanks! But this is only half-way
around the problem. Now I can read them in the browser,
thats neat, but my ISAPI extension needs the variables,
and your suggestion about ContentFromStream


The TStream contains a bunchs of properties and methods,
and to be frank I don't know my around that!

function ContentFromStream(Stream: TStream): string; override;

This is getting complex, I am upping the points for this.

GOMF
Avatar of GOMF

ASKER

Adjusted points to 400
Hi GOMF,

I'm currently at work so it have to wait till I'm home :O(.
But as a starter in the field of ISAPI, I can try to read in the variables out of the stream into your ISAPI extensions. Maybe you can mail me a few pieces of your code where the variables need to be read or where you goin' to use these.

email is mulbum@worldonline.nl

Maybe 10 hours from now I'll be back on this one, because it's getting interesting.
:O)
brUINTje.

Avatar of GOMF

ASKER



bruintje,

This doesn't return anything

<A HREF = "http://<%= Request.ServerVariables("SERVER_NAME") %> "></A>



I wonder why ?

GOMF
Avatar of GOMF

ASKER

bruintje,

This doesn't do it :(


GOMF
Hi GOMF,

Could you send me some code fragments so I can start up a bit.

my email adress

mulbum@worldonline.nl

I will get back soon.
:O)
brUINTje
Sorry for that second request my head is a bit spinning today............
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GOMF

ASKER


Much obliged for the "stakes" you took to help me out there.


Best wishes!


GOMF