Submitting Variables from a Delphi EXE to a Web Page

Looking for the easiest way to submit a variable generated from within a Delphi application (standalone exe) to a web page, where it is processed by an ISAPI dll, and the processed value returned to the application. Done a lot of Delhi development, but not much in the way of web programming. Can anyone help?

Who is Participating?
Eddie ShipmanConnect With a Mentor All-around developerCommented:
Ok, here you go...

PHP Code:
  $input = $_GET["inputvalue"];
  $i1 = $input[0];
  $i2 = $input[1];
  $i3 = $input[2];
  $i4 = $input[3];
  $i5 = $input[4];
  $i6 = $input[5];
  $itot = $i1+($i2*2)+($i3*3)+($i4*4)+($i5*5)+($i6*6)+$input;
  echo $itot;

Delphi Code:
procedure TForm1.Button1Click(Sender: TObject);
  s1, s2: String;
  i1, i2, i3, i4, i5, i6: Integer;
  s1 := EditInput.Text;
  // Check Box named chkUsePHP determines
  // if we use the PHP script or the below Delphi
  //code for testing.
  if chkUsePHP.Checked then
    // Use the PHP script
    s2 := idHTTP1.Get('http://localhost/makenum.php?inputvalue='+s1);
    // Use Delphi code to test results
    i1 := StrToInt(s1[1]);
    i2 := StrToInt(s1[2]) * 2;
    i3 := StrToInt(s1[3]) * 3;
    i4 := StrToInt(s1[4]) * 4;
    i5 := StrToInt(s1[5]) * 5;
    i6 := StrToInt(s1[6]) * 6;
    i1 := i1 + i2 + i3 + i4 + i5 + i6 + StrToInt(s1);
    s2 := IntToStr(i1);
  EditCode.Text := s2;
Eddie ShipmanAll-around developerCommented:
Use TidHTTP:
If you can tell me what you are sending and what you expect as a return value, I can whip
something up for you very quickly.
Eddie ShipmanAll-around developerCommented:
Is the ISAPI expecting a GET or a POST?
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Eddie ShipmanAll-around developerCommented:
Do you already have a web page that does this action?
JDJVRAuthor Commented:
Hi Eddie

I have to design everything from scratch - a portion of the exe, ISAPI, and web page. The whole thing boils down to the following process:
1. I click a button in the exe and this opens a web page on which a Web app (dll) resides. An integer variable is submitted from the exe to the web page to be used by the dll.
2. The dll uses the variable to calculate a return value. (also integer)
3. This return value is passed back to the exe and displayed in a text box on the exe GUI.

I know this is almost like requesting a tutorial, but the Delphi documentation do not offer much in the way of examples (is this an understatement??) and I need to have a clear understanding of the principles involved before diving in and making a hash of it. Since the architecture of the ISAPI is not cast in stone yet, I am open to suggestion as to the best way to proceed.


the most simple way will be creating a url that contains your data and connecting it.

your isapi dll will receive following parameters from this GET request

then your isapi generates a response page and your delphi application can parse it.

a more advanced (read elegant) way is using XML as a data format for both request and response, for more information take a look at
Eddie ShipmanAll-around developerCommented:
Are you against using something like PHP instead of ISAPI? PHP is very easy to use and learn and very easy
to setup on your web server or find a host that provides it.

I use PHP on a site that I maintain for a local baseball league and can use a Delphi to update the scores in
a mySQL database using idHTTP from Indy.

Without having something to test against, you may be grasping at straws. I agree with alikoank that you submit
the values either in a GET request, where the values you want to pass are in the URL, or in a POST where the
values will be sent via PostVars.

I posted a sample of how to post data to an asp page and get a return value here:

If you want more info on how to do the PHP end of things, feel free to contact me again.
JDJVRAuthor Commented:
Hi Eddie & alikoank

Thanks for the responses. It seems that GET and POST as described by alikoank will do the trick - the required function to be fulfilled by the dll is not very complex. Of PHP I know the proverbial zero - could you direct me to a GOOD reference site for more info?

Eddie ShipmanAll-around developerCommented: is one that I frequent. PHP isn't very difficult, especially if you know Java or C.
If you only know Delphi, it is a little more difficult to grasp some of the concepts.

What exactly do you want to do to these variables and what do you want to return?
JDJVRAuthor Commented:
Basically what the EXE does is to present the web page with an integer code generated from a variety of computer hardware and software serial numbers, which is then reworked and converted into an encrypted integer code and passed back to the EXE. This unlocks certain functionality on the EXE. (converting the program from a demo to fullly functional version). I am not fluent in either Java or C, but did some extensive study of HTML, XHTML and XML to get acquainted with web page architecture a couple of weeks ago. Must say I found those quite easy - also had a quick look at some Java scripts which did not appear totally confusing.

My main concern at this point is just to get the job done as quickly as possible - a value must be passed from the EXE to the web page, and another back to the EXE, preferably within the framework of my knowledge of Delphi and HTML. By the way, the web page will be hosted on a computer running some flavour of Unix - so my dll will be developed cross-platform and compiled in Kylix.
Eddie ShipmanAll-around developerCommented:
Why go to the trouble of building the ISAPI when you can have PHP running in < 1 hr.

If you give me some sort of idea how to manipulate the data, including some sample
input and what you are expecting as output, I could probably write something up in PHP
fairly quickly. Then I could show you how to pass this info from the Delphi EXE to the PHP
script and get the result back into the EXE.
Eddie ShipmanAll-around developerCommented:
I'll even place a copy of the script on my site so you can test it before installing it on your site.
JDJVRAuthor Commented:
Hi Eddie
For the purposes of illustration, let us keep the number crunching simple. Let's say the EXE outputs a 6-digit value 654321 and assigns it to a global integer variable idNum in the EXE. This value is passed to the web page, where it is converted into a string variable, idStr. The string is then dissected into single digits, each of which is again changed into integer, and multiplied with its position in the string, and added up. (I.e. 6x1 + 5x2 + 4x3 + 3x4 + 2x5 + 1x6) This total is added to the original idNum value and returned to the exe to be displayed in an Edit box, say EditCode. That's it. I should be able to follow the logic.

Thanks for your patience.
Eddie ShipmanAll-around developerCommented:
Very simple, I'll have it to you shortly.
dump a Twebrowser on the form make it hidden, then point it to the DLL with the varibles in the URL


 you can then read the source returned using this code

Eddie ShipmanAll-around developerCommented:
Ok, In your example the result would be 654377, correct?
Eddie ShipmanAll-around developerCommented:
Change the URL in the idHTTP.Get to wherever you place the PHP code.
You can use localhost for testing. If you have XP/2K, you can just install it
in the \Inetpub\wwwroot directory and test locally.

Be sure to install PHP first, however. You can download it from

Any more questions, let me know.
JDJVRAuthor Commented:
Thanks everyone, especially EddieShipman. Think I can take it from here. Got myself a fat PHP book and I'm halfway through it already - you were right, PHP is easy.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.