[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • Last Modified:

Reading an environment variable

Hello folks!

I have VERY embarassing question ;-)

HOW DO I READ AN ENVIRONMENT VARIABLE IN DELPHI ?

Forgive me ;-)


GOMF
0
GOMF
Asked:
GOMF
  • 10
  • 8
  • 4
1 Solution
 
MadshiCommented:
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
 
GOMFAuthor Commented:
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
 
GOMFAuthor Commented:
Above ;-)

GOMF
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MadshiCommented:
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
 
GOMFAuthor Commented:
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
 
GOMFAuthor Commented:
Adjusted points to 250
0
 
MadshiCommented:
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
 
GOMFAuthor Commented:
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
 
MadshiCommented:
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
 
bruintjeCommented:
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
 
bruintjeCommented:
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
 
bruintjeCommented:
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
 
bruintjeCommented:
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
 
GOMFAuthor Commented:
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
 
GOMFAuthor Commented:
Adjusted points to 400
0
 
bruintjeCommented:
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
 
GOMFAuthor Commented:


bruintje,

This doesn't return anything

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



I wonder why ?

GOMF
0
 
GOMFAuthor Commented:
bruintje,

This doesn't do it :(


GOMF
0
 
bruintjeCommented:
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
 
bruintjeCommented:
Sorry for that second request my head is a bit spinning today............
0
 
bruintjeCommented:
Hi,

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

:O)
bruintje.
0
 
GOMFAuthor Commented:

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


Best wishes!


GOMF
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 10
  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now