• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Submitting Variables from a Delphi EXE to a Web Page

Hello
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?

JDJVR
0
JDJVR
Asked:
JDJVR
1 Solution
 
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.
0
 
Eddie ShipmanAll-around developerCommented:
Is the ISAPI expecting a GET or a POST?
0
 
Eddie ShipmanAll-around developerCommented:
Do you already have a web page that does this action?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.

Thanks

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

http://my.server.com/test.cgi?name=jdjvr&points=125&topic=delphi

your isapi dll will receive following parameters from this GET request
name=jdjvr
points=125
topic=delphi

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

http://delphi.about.com/od/webservices/
0
 
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:
http://www.delphipages.com/threads/thread.cfm?ID=97550&G=97434

If you want more info on how to do the PHP end of things, feel free to contact me again.
0
 
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?

JDJVR
0
 
Eddie ShipmanAll-around developerCommented:
http://www.phpbuilder.com 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?
0
 
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.
0
 
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.
0
 
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.
0
 
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.
0
 
Eddie ShipmanAll-around developerCommented:
Very simple, I'll have it to you shortly.
0
 
DavidBirch2dotComCommented:
dump a Twebrowser on the form make it hidden, then point it to the DLL with the varibles in the URL

WebBrowser1.Navigate('www.mysite.com/cgi-bin/my.dll?var1=2&var2=3');

 you can then read the source returned using this code

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21073169.html

David
0
 
Eddie ShipmanAll-around developerCommented:
Ok, In your example the result would be 654377, correct?
0
 
Eddie ShipmanAll-around developerCommented:
Ok, here you go...

PHP Code:
<?php
  $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);
var
  s1, s2: String;
  i1, i2, i3, i4, i5, i6: Integer;
begin
  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
  begin
    // Use the PHP script
    s2 := idHTTP1.Get('http://localhost/makenum.php?inputvalue='+s1);
  end
  else
  begin
    // 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);
  end;
  EditCode.Text := s2;
end;
0
 
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
http://www.php.net

Any more questions, let me know.
0
 
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.

Regards
JDJVR
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now