Solved

Reading an environment variable

Posted on 1999-01-12
22
484 Views
Last Modified: 2010-04-06
Hello folks!

I have VERY embarassing question ;-)

HOW DO I READ AN ENVIRONMENT VARIABLE IN DELPHI ?

Forgive me ;-)


GOMF
0
Comment
Question by:GOMF
  • 10
  • 8
  • 4
22 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1356049
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.
0
 

Author Comment

by:GOMF
ID: 1356050
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.
0
 

Author Comment

by:GOMF
ID: 1356051
Above ;-)

GOMF
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 20

Expert Comment

by:Madshi
ID: 1356052
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.
0
 

Author Comment

by:GOMF
ID: 1356053
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
0
 

Author Comment

by:GOMF
ID: 1356054
Adjusted points to 250
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356055
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.
0
 

Author Comment

by:GOMF
ID: 1356056
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
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1356057
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.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356058
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.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356059
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
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356060
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.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356061
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.
0
 

Author Comment

by:GOMF
ID: 1356062
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
0
 

Author Comment

by:GOMF
ID: 1356063
Adjusted points to 400
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356064
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.

0
 

Author Comment

by:GOMF
ID: 1356065


bruintje,

This doesn't return anything

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



I wonder why ?

GOMF
0
 

Author Comment

by:GOMF
ID: 1356066
bruintje,

This doesn't do it :(


GOMF
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356067
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
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1356068
Sorry for that second request my head is a bit spinning today............
0
 
LVL 44

Accepted Solution

by:
bruintje earned 400 total points
ID: 1356069
Hi,

Well, I'm glad that the suggestions about the TWebRequest led you indirectly in the right direction.

:O)
bruintje.
0
 

Author Comment

by:GOMF
ID: 1356070

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


Best wishes!


GOMF
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 221
FMX enumerated colours 2 115
Help on project with Soap 10 57
select query - oracle 16 100
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question