Solved

Submitting Variables from a Delphi EXE to a Web Page

Posted on 2004-08-11
18
284 Views
Last Modified: 2010-05-18
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
Comment
Question by:JDJVR
18 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11777572
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11777580
Is the ISAPI expecting a GET or a POST?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11777584
Do you already have a web page that does this action?
0
 

Author Comment

by:JDJVR
ID: 11780986
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
 
LVL 4

Expert Comment

by:alikoank
ID: 11780990
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11783570
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
 

Author Comment

by:JDJVR
ID: 11784599
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11786525
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
 

Author Comment

by:JDJVR
ID: 11787150
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 26

Expert Comment

by:EddieShipman
ID: 11788174
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11788179
I'll even place a copy of the script on my site so you can test it before installing it on your site.
0
 

Author Comment

by:JDJVR
ID: 11790894
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11791904
Very simple, I'll have it to you shortly.
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11792192
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11793156
Ok, In your example the result would be 654377, correct?
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 125 total points
ID: 11793280
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 11793301
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
 

Author Comment

by:JDJVR
ID: 11796693
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Firewall issues 6 85
System restore point 4 78
Thread safe  opinion 7 111
Print Graphic and Text to Epson TM-T88v 12 114
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now