how to send data to server

hi
 i have a simple form and from have a TEdit box i want to send it to the server on button click.

unit unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, XP_Button, CoolTrayIcon, ImgList, StdCtrls, Menus;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    ImageList1: TImageList;
    CoolTrayIcon1: TCoolTrayIcon;
    tfXPButton1: TtfXPButton;
    PopupMenu1: TPopupMenu;
    show1: TMenuItem;
    hide1: TMenuItem;
    logout1: TMenuItem;
    exit1: TMenuItem;
    N1: TMenuItem;
    N2: TMenuItem;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    procedure tfXPButton1Click(Sender: TObject);
  private
    { Private declarations }
  public

    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.tfXPButton1Click(Sender: TObject);
begin
{

code for data sending

}
 application.Minimize;
end;

end.



suggest me i m newbe in delphi.


thanx



kim_rayAsked:
Who is Participating?
 
Geert GConnect With a Mentor Oracle dbaCommented:
here is an example:

First
Put a webbrowser component in the form
and you 'll need a TButton (or something you can click too)

Second
Create an event handler for the OnDocumentComplete event of the WebBrowser

Third
you need to load the page in the WebBrowser
I do it with an Edit to enter the webpage and a btn to load the page:

procedure TForm1.btnClick(Sender: TObject);
begin
  // edUrl.Text = 'http://www.google.be';  
  // wb = webbrowser component
  wb.Navigate2(edUrl.Text);
end;

Fourth
Probably you will be needing to navigate in the WebBrowser to the correct page for the data entry

Fifth
Right click and hit "View Source"
Each field that must get a value has a unique id
like for the www.google.be i look for the entry field and the button with type submit
be aware, there can be more than 1 form
i found:
for the form
<form action="/search" name=f>
for the edit
<input maxlength=2048 name=q size=55 title="Google zoeken" value="">
for the button
<input name=btnG type=submit value="Google zoeken">
now we have the name of the elements we want to fill in:
edit: q
btn: btnG
form: f

Sixth:
we will need to fill in the data into the Html Form

procedure TForm1.btnSetValuesClick(Sender: TObject);
var
  IDoc3: IHTMLDocument3;
  Elem1: WideString;
begin
  Elem1 := 'q';
  IDoc3 := wb.Document as IHTMLDocument3;
  IDoc3.getElementById(Elem1).setAttribute('value', editSearch.Text, 0);
end;

Seventh:
Hit the submit button:
procedure TForm1.btnSubmitClick(Sender: TObject);
var
  IDoc3: IHTMLDocument3;
  IDoc2: IHTMLDocument2;
  IForm: IHTMLFormElement;
  Elem1: WideString;
begin
  Elem1 := 'f';
  IDoc3 := wb.Document as IHTMLDocument3;
  IDoc2 := IDoc3 as IHTMLDocument2;
  IForm := (IDoc2.forms.item(Elem1, 0)) as IHTMLFormElement;
  IForm.submit;
end;

note:
in your implementation uses you need to add the type Library MSHTML_TLB
From project choose Import Type Library (Microsoft HTML Object Library Version 4.0)
(or better version)

That's all folks !!!
G
0
 
Cedric_DCommented:
procedure TForm1.tfXPButton1Click(Sender: TObject);
begin

  SendToServer(Edit1.Text);

  application.Minimize;
end;
0
 
Geert GOracle dbaCommented:
what type of server do you mean ?

a database ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
kim_rayAuthor Commented:
basically i have a url just like
http://www.abcd.com?name=aaaa&college=bbbbb
i want to send name and college from the button click
 
 
0
 
Geert GOracle dbaCommented:
you are opening a webpage with internet explorer (or any other browser)
and in your application you want to send the name and college ?
0
 
kim_rayAuthor Commented:
simple i want to send the name and college only.
i know navigatefromband() opens the webpage with internet explorer
0
 
Geert GOracle dbaCommented:
simple ?

you need to recreate the HTTP request that's inside the HTML code
you don't even have a webbrowser in your form to get to the html code

you want to fill in the name and college in internet explorer with delphi and hit the submit button in internet explorer ?
0
 
Cedric_DCommented:
If you want to combine URL from Edit-fields, you may use:

var URL: string;

...

URL = 'http://www.abcd.com?name=' + Edit1.Text + '&college=' + Edit2.Text;

navigatefromband(URL);
0
 
Geert GOracle dbaCommented:
that's not sending, that's navigating to a new page
0
 
TheRealLokiSenior DeveloperCommented:
lol Cedric D, your first post cracks me up,
perfect answer to a imperfect question :-D

kim ray, you still need to be more specific.
Do you just want to use a WebBrowser within delphi
e.g.
webbrowser1.Navigate('http://www.abcd.com?name=' + Edit1.Text + '&college=' + Edit2.Text);

or do you want to spawn Internet Explorer (or irefox, or whatever the defult browser is)
e.g.
ShellExecute(Handle, 'open', PChar('http://www.abcd.com?name=' + Edit1.Text + '&college=' + Edit2.Text), nil, nil, sw_show);
?


0
 
Geert GOracle dbaCommented:
sending from delphi would be:
opening a webpage in a webbrowser on a delphi form
filling in the edit fields inside of the webbrowser
and hitting the submit button with delphi ...
0
 
kim_rayAuthor Commented:
thanx Geert_Gruwez but how can i hit the submit button through out the delphi.
0
 
Geert GOracle dbaCommented:
a B ?
not read the EE recommendations on grading a Question yet ?
0
 
Geert GOracle dbaCommented:
was anything not working from my answer ?
0
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.