Solved

CGI with Delphi - Output written to a file

Posted on 1998-03-11
4
378 Views
Last Modified: 2013-11-18
I am working on a CGI program written in Delphi. It accesses a database.  From what I have read and the examples I have seen, data is sent back by first writting it to an output file on the server.  From what I understand ( I am new at this ), the output file name is specified in the an INI file on the server.  Therefore, the output file is always the same.  So what happens if two peoples use the CGI program at the same time ? Do they both write to the same output file and overwrite each other or would there be an error returned ?

Also, I am just starting to read about ISAPI. Is it better ?
0
Comment
Question by:skylinka
  • 2
4 Comments
 

Author Comment

by:skylinka
ID: 1360424
Edited text of question
0
 
LVL 3

Expert Comment

by:williams2
ID: 1360425
Ok my friend, I've got know exactly what you want!
1. The HTML file first:
<html><title>Testing CGI</title><body>
<form action="http://localhost/cgi-win/test.exe" method=post>
Søgeord:
<input type= text name= searchfield1 size=20><br>
<input type=submit value="Søg">
</form></body></html>

This you have probably seen before, the Test.exe is placed in the  CGI-WIN folder (Using Website Server).
The produced INI file is given to the EXE file (Read it with  ParamStr(1) ). The INI file contains:

 [CGI]
 Request Protocol=HTTP/1.0
 Request Method=POST
 Request Keep-Alive=No
 Document Root=C:\WEBSITE\HTDOCS\
 Executable Path=/cgi-win/test.exe
 Server Software=WebSite/1.1e
 Server Name=10.2.100.138
 Server Port=80
 Server Admin=Williams@aabc.dk
 CGI Version=CGI/1.3 (Win)
 Remote Address=127.0.0.1
 Referer=file://www.aabc.dk/Test.htm
 User Agent=Mozilla/3.01 [da] (Win95; I)
 Content Type=application/x-www-form-urlencoded
 Content Length=81
 
 [System]
 GMT Offset=3600
 Debug Mode=No
 Output File=C:\Website\CGI-Temp\43ws.htm
 Content File= C:\Website\CGI-Temp\43ws.inp
 
 [Form Literal]
 searchfield1=Thomas

 [Accept]
 image/gif=Yes
 image/x-xbitmap=Yes
 image/jpeg=Yes
 image/pjpeg=Yes
 */*=Yes

 [Extra Headers]
 Host=localhost

The Outputfile will contain the string: "C:\Website\CGI-Temp\43ws.htm"
This means, that you have to write to axctly that filename. The Server program will handle it afterwards.
The "43ws.INP" contains the inputinformation from the user, but you allready got them here under the [Form Litteral] topic.

And now to the program example:

Program Test;

Uses IniFiles;

  Procedure ProcessScript;
  var
     IniFile: TInifile;
     filename: string;
     f: Textfile; //Same as 'File of Text'
  begin
     IniFile:= TInifile.create(Paramstr(1)); // Paramstr(1)

     // *** header begin ***

     filename:= IniFile.Readstring('System','Output File','');
     assignfile(f,filename);
     rewrite(f); // Create output file
     writeln(f,'HTTP/1.0 200 OK');
     writeln(f,'Date: Friday, 28 Nov-97, 13:36:12 GMT');
     writeln(f,'Server:Website/1.1e');
     writeln(f,'Allow-ranges: bytes');
     writeln(f,'Content-type: text/html');
     writeln(f,'Content-length: 0');
     writeln(f);
     writeln(f,'<HTML>');
     writeln(f,'<Title>Result</Title>');
     writeln(f,'<Body>');
     writeln(f,'<body background = http://mis.lamar.edu/mis/Grundy/parchmen.gif>');
     writeln(f,'The following matched the query: <BR><BR>');

     // *** header end ***

     GetData(IniFile); // Hand over the Inifile to the 'GetData' procedure, to finish the query.
     WriteResult(f);

     writeln(f,'</body>');
     writeln(f,'</HTML>');
     Closefile(f);
  end;

Begin
  ProcessScript;
end.

As you see, the file to be read/written is NOT THE SAME, they should actually be rather distinguished from each other. You can freely decide what to send back.

If you like more information, I can supply in the building of both DDE-Servers etc. (It's rather slow opening and initializing a DBase and close it down every time, and it's ressource demanding too. The Server will keep it open!)
0
 

Expert Comment

by:ymailhot
ID: 1360426
Thank you for your answer. My concern is if two peoples run the CGI at the same time and therefore write to the same output file. Is that possible ?
0
 
LVL 3

Accepted Solution

by:
williams2 earned 100 total points
ID: 1360427
Yes! ..That's exactly what I mean! ..The Server provides a unique name for the outputfile, namely the outputfile specified in the .INI file. I've been testing this running up to 10 queries at the same time in different varities. The outputfilename is NOT trivial, it's ALWAYS different. That you don't need to take care of, it's provided by the service in generel.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now