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

Webrowser

I have to write a Delphi 5 program to send to a HTTP site 1 line of text to send SMS to selected numbers using WebBrowser1
e.g
'http://gateway.sitename.com.au/sendSMS?UserName=kevin&Password=test10&Recipient=0478111111&Message=This%20is%20a%20message&Sender=0438212142';

The Webbrowser1 shows messages 0 Successfull 10 error etc
How can I read the WebBrowser text to get the error number so I can display it in a form the user can understand
0
Kevinfeening
Asked:
Kevinfeening
1 Solution
 
epasquierCommented:
you have to analyse the HTML, find the tags that are delimiting your error code and other useful info

it all start by getting the Document interface of your loaded page , then using it to walk through the elements to identify key tags, and the text that might be after or inside a open/close tag pair
Here is MSDN reference for that :
http://msdn.microsoft.com/en-us/library/aa752574%28VS.85%29.aspx

Note that there are many Document interfaces, that have been added with different versions of IE, among which the 2 & 3 are the most usefull.
You will also have to be familiar with the IHTMLElementCollection interface, as many Document crawling involve getting collection of elements, either by asking all that correspond to a certain tag, or get all childs of one element etc...

Here are a few examples to get you started


var
   Document2 : IHTMLDocument2;
   Document3 : IHTMLDocument3;
   Collection: IHTMLElementCollection;
   Element   : IHTMLElement;
   i:integer;
   TextInsideTableCell:String;
begin
 Document2:=Webbrowser.Document As IHTMLDocument2;
 Document3:=Webbrowser.DocumentAs IHTMLDocument3;
 Collection:=Document2.All; // All elements in your HTML, including header !
 Collection:=Document2.Body; // All elements of the body, usually a good start
 Collection:=Document3.getElementsByTagName('a'); // a good way of getting all links
 Collection:=Document3.getElementsByTagName('tr'); // get all table rows
 for i:=0 to Collection.Length-1 do 
  begin
   Element:=Collection.Item(i,'') as IHTMLElement;
   if Element.TagName='td' Then 
    begin
     TextInsideTableCell:=Element.InnerHTML;
    end;
  end;
end;

Open in new window

0
 
Mahdi78Commented:
To receive response text from HTTP server and put it in TMemo, use the following even of TWebBrowser

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
Memo1.Text := WebBrowser1.OleObject.Document.documentElement.innerText;
end;
0
 
KevinfeeningAuthor Commented:
Worked Perfectly thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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