Solved

A simple Delphi CGI application.

Posted on 2001-09-13
5
537 Views
Last Modified: 2013-11-18
Could someone do me a walk-through description of creating a Delphi CGI application that simply accepts a variable (person's name) and creates a HTML page that says hello to that person?

My server-side scripting is okay, and I get how it works, but don't know how to create it in Delphi.  (Just got some web space on an NT server.)

Thanks,

John.
0
Comment
Question by:Jaymol
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6478826
Hello

I prefer to use ISAPI, it's better than CGI and have more benefits more than the CGI

here's a good site for ISAPI Tutorials, it fully made by delphi

http://www.matlus.com/scripts/website.dll

and here's some link for CGI

delphi and CGI
http://www.drbob42.com/books/cgi.htm
http://www.drbob42.com/books/cgi-data.htm


Writing a fancy CGI hit counter in Delphi 5
http://homepages.borland.com/aohlsson/Articles/CounterCGI.html

Web Programming in Delphi
http://www.209software.com/books/wpid/ 

Best regards
Mohammed Nasman
0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 6479465
Hi John,

1.From File-New select 'Web server app'.
2.From the next menu select 'CGI standalone exe'.
3.You will see a tree WebModule1-Actions. Select 'Actions', right-click on it and select 'Add Item' from the popup menu. WebActionItem1 appears.
4.Select that item and change its 'Default' property to True - this means that that item will be executed on every request.
5.Create an OnAction event handler for that item like the following:

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  UserName : string;
begin
  UserName := Request.QueryFields.Values['name'];
  Response.Content := '<HTML><BODY>Hello ' + UserName + '</BODY></HTML>';
  Response.SendResponse;
  Handled := True;
end;

6.Build the CGI app as 'MyCGI.exe' for example and place it on the server.

7. Calling your app from a html page:
Your html link to call that CGI should look like:

<A HREF="www.hostname.com/path/MyCGI.exe?name=John">Click me</A>

Here 'name' is a query field and 'John' is its value, which value will be passed to your app.

Another way:
If you want to use a html form for calling your app, then 1.Change the WebActionItem1 'MethodType' property from mtAny to mtPost. (optional)
2.In the code above use 'ContentFields' instead of 'QueryFields'.
3.Call the app from a html page like:

<HTML>
<HEAD><TITLE><Test Hello CGI></TITLE></HEAD>
<BODY>
<FORM METHOD=POST ACTION="www.hostname.com/path/MyCGI.exe">
<INPUT TYPE=text NAME="name"  VALUE="">
<INPUT TYPE=submit VALUE="Submit">
</FORM>
</BODY>
</HTML>

Regards, Geo
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6486930
Thanks for your help.

John.
0
 
LVL 17

Expert Comment

by:geobul
ID: 6487069
You are welcome.

Regards, Geo
0
 
LVL 6

Author Comment

by:Jaymol
ID: 6487100
Geo, could you look at the other question I have open?

John.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

786 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