CGI with Delphi - Output written to a file

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 ?
skylinkaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

skylinkaAuthor Commented:
Edited text of question
0
williams2Commented:
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
ymailhotCommented:
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
williams2Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.