Solved

CGI with Delphi - Output written to a file

Posted on 1998-03-11
4
381 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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