Solved

CGI with Delphi - Output written to a file

Posted on 1998-03-11
4
384 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SUM 2 INTEGER ARRAYS INTO 1 10 111
I want to use librsync in my Delphi backup application. 3 69
update joined tables 2 62
Grunt script for Build Process 1 63
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

756 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