Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2006, 01:39 PM
grashopper grashopper is offline
Member
 
Join Date: Mar 2005
Posts: 56
Default use delphi to autocomplete form in twebbrowser ???

Using D5 ...
I used to be able to build a url to retrieve a street map. eg 'http://www.whereis.com.au/streetnumber=&56&,streetname=&Maryland St&,suburb=&Stanthorpe&,state=&Queensland&'

Now the site has changed the way it works & instead of building a url like the above it loads a script variable
WhereisAddress{streetNumber='null', fullStreetName='null', suburb='null', state='null', poiCode='null', poiSuburb='null', poiState='null', addressType='0', addressKey='null'}
(or whereisaddress.streetnumber, whereis.streetname etc etc)
which it feeds to its engine to display the map

Using twebbrowser (or a replacement) is it possible
a) to load this variable directly from my app & execute the 'onclick' script or
b) autocomplete the form entries where the form embedded in the html is called mapform and has fieldsets formatted as below (& execte the script ?)




etc etc


TIA
Kim
Reply With Quote
  #2  
Old 05-06-2006, 02:06 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: use delphi to autocomplete form in twebbrowser ???

hi,

use the Twebbrowser from delphi

=========
sample 1
=========

[DELPHI]{ To test this code put a TWebBrowser and A TButton component on the form }


function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;
//no form on document
if WebBrowser.OleObject.Document.all.tags('FORM').Len gth = 0 then
begin
Exit;
end;
//count forms on document
for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
begin
FormItem := WebBrowser.OleObject.Document.forms.Item(I);
for j := 0 to FormItem.Length - 1 do
begin
try
//when the fieldname is found, try to fill out
if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
Exit;
end;
end;
end;
end;


//When the document is complete try to fill out the field homepage with the url
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
if FillForm(WebBrowser1, 'homepage', 'http://www.swissdelphicenter.ch') = False then
ShowMessage('Error. Field not available or no Form found.');
end;

// Show the Webbrowser-Progress in Label1
procedure TForm1.WebBrowser1ProgressChange(Sender: TObject; Progress, ProgressMax: Integer);
begin
if ProgressMax = 0 then
begin
label1.Caption := '';
Exit;
end;
try
if (Progress <> -1) and (Progress <= ProgressMax) then
label1.Caption := IntToStr((Progress * 100) div ProgressMax) + '% loaded...'
else
label1.Caption := '';
except
on EDivByZero do Exit;
end;
end;


//For example you can load the page /en/addtip.php to the TWebBrowser
//When the document is Complete the form where you can put your homepage
//address is filled out
procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/addtip.php');
// Show the Titel of the currently active Webpage in the titlebar
// Den Titel der aktuellen Webseite in der Titeleiste anzeigen
Caption := Webbrowser1.OleObject.Document.Title;
end;[/DELPHI]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #3  
Old 05-06-2006, 02:08 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: use delphi to autocomplete form in twebbrowser ???

=========
sample 2
=========

[DELPHI]{
This example shows how to automatically fill in a search string
in the "Search Tip" page and click the search button.
}

uses
MSHTML_TLB;

// first navigate to tipspage

procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http://www.swissdelphicenter.ch/en/tipsuchen.php');
end;

// Try to access IE instance and fill out the search field with
// a text and click the search button

procedure TForm1.Button3Click(Sender: TObject);
var
hIE: HWND;
ShellWindow: IShellWindows;
WB: IWebbrowser2;
spDisp: IDispatch;
IDoc1: IHTMLDocument2;
Document: Variant;
k, m: Integer;
ovElements: OleVariant;
i: Integer;
begin
ShellWindow := CoShellWindows.Create;
// get the running instance of Internet Explorer
for k := 0 to ShellWindow.Count do
begin
spDisp := ShellWindow.Item(k);
if spDisp = nil then Continue;
// QueryInterface determines if an interface can be used with an object
spDisp.QueryInterface(iWebBrowser2, WB);

if WB <> nil then
begin
WB.Document.QueryInterface(IHTMLDocument2, iDoc1);
if iDoc1 <> nil then
begin
WB := ShellWindow.Item(k) as IWebbrowser2;
begin
Document := WB.Document;

// count forms on document and iterate through its forms
for m := 0 to Document.forms.Length - 1 do
begin
ovElements := Document.forms.Item(m).elements;
// iterate through elements
for i := 0 to ovElements.Length - 1 do
begin
// when input fieldname is found, try to fill out
try
if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and
(CompareText(ovElements.item(i).type, 'text') = 0) then
begin
ovElements.item(i).Value := 'FindWindow';
end;
except
end;
// when Submit button is found, try to click
try
if (CompareText(ovElements.item(i).tagName, 'INPUT') = 0) and
(CompareText(ovElements.item(i).type, 'SUBMIT') = 0) and
(ovElements.item(i).Value = 'Search') then // Suchen für German
begin
ovElements.item(i).Click;
end;
except
end;
end;
end;
end;
end;
end;
end;
end;[/DELPHI]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #4  
Old 05-06-2006, 02:35 PM
grashopper grashopper is offline
Member
 
Join Date: Mar 2005
Posts: 56
Default RE: use delphi to autocomplete form in twebbrowser ???

Barao,
many thanks for your very quick response ..

I am trying method 1 at the moment & I am getting a 'Method 'Name' not supported by automation object error' EOLeException - in the loop I am just trying to show the fieldnames to make sure I have them correctly

Any ideas (my IE version is 7beta2 if that helps)
Kim
Reply With Quote
  #5  
Old 05-06-2006, 02:55 PM
grashopper grashopper is offline
Member
 
Join Date: Mar 2005
Posts: 56
Default RE: use delphi to autocomplete form in twebbrowser ???

Barao,
I have just tried this method as well & spdisp is nil when executed (the webbrowser component is loaded with the page) if I open an instance of IE it duly fills in the fields with 'Findwindow' as intended

Kim
Reply With Quote
  #6  
Old 05-07-2006, 04:38 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: use delphi to autocomplete form in twebbrowser ???

remove the default twebbrowser that comes from delphi and import again using the update twebbrowser

http://www.euromind.com/iedelphi/getting_started.htm

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #7  
Old 05-07-2006, 04:43 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: use delphi to autocomplete form in twebbrowser ???

before update the twebbrowser,
try read this two threads about twebbrowser..

[link]http://www.delphipages.com/threads/thread.cfm?ID=75957&G=75957[/link]

[link]http://www.delphipages.com/threads/thread.cfm?ID=66251&G=66251[/link]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #8  
Old 05-07-2006, 04:44 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,577
Default RE: use delphi to autocomplete form in twebbrowser ???

before update the twebbrowser,
try read these two threads about twebbrowser..

[link]http://www.delphipages.com/threads/thread.cfm?ID=75957&G=75957[/link]

[link]http://www.delphipages.com/threads/thread.cfm?ID=66251&G=66251[/link]

Regards
BaraoZemo

ps, don't forget to click in the button and Accept as Answer if this helped you!
Reply With Quote
  #9  
Old 05-07-2006, 02:22 PM
grashopper grashopper is offline
Member
 
Join Date: Mar 2005
Posts: 56
Default RE: use delphi to autocomplete form in twebbrowser

Found the problem with the basis of the answer -
the form has a mixture of things on it(lists and buttons) & it needed the addition of a single test to test the tagname is 'input'
eg
for j := 0 to FormItem.Length - 1 do
begin
try
formdata := FormItem.Item(j);
if formdata.tagname = 'INPUT' then <--------
begin
// when the fieldname is found, try to fill out
if formdata.Name = fieldname then
begin
FormItem.Item(j).Value := value;
Result := True;
end;
end;
except
Exit;
end;
end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 06:32 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.