How to use WebDispatcher to retrieve data

I have a URL that delivers a page response that I can interrogate.

In VCL this is (relatively) simple, using a TWebBrowser component: WebBrowser1.Navigate(RequestURL), and then interrogating the response in a WebBrowser1NavigateComplete2 function

How do you do this in FireMonkey?
GrahamDLovellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukCommented:
Look at this blog. Depending on Delphi version - there are few options. Mostly third part.
One is webfmx.
0
GrahamDLovellAuthor Commented:
Thanks for your response Sinisa. After some exploring, I found you could use TWebBrowser on a Windows implementation of a mobile app (The doco says it is not available for "desktop applications in Fire Monkey", but this did not rule it out in this case).

Actually it is quite simple in Fire Monkey - easier than in VCL.

I found that Embarcadero's Tutorial leads you through adding a TWebBrowser in a mobile, and it starts with a TToolbar component. I couldn't do that, as I didn't have room on the screen. I wanted my WebBrowser to work behind the scenes.

So here goes:
uses
  SHDocVw, mshtml;

type

TfMMain = class(TForm)
...
private
    WebBrowser: TWebBrowser;
end;

procedure TfMMain.FormActivate(Sender: TObject);
begin
  WebBrowser := TWebBrowser.Create(Self);
end;

procedure TfMMain.GetKey;
var
   Data1: IHTMLElement;
   Memo1: TMemo;
  RequestURL: string;
begin
 ... fill in RequestURL ...
  WebBrowser.Navigate(RequestURL);
  while (WebBrowser.ReadyState < READYSTATE_INTERACTIVE) do
       Application.ProcessMessages;
  if Assigned(WebBrowser.Document) then
  begin
    Memo1 := TMemo.Create(fMMain);
    try
     Data1 := (WebBrowser.Document AS IHTMLDocument2).body;
     while Data1.parentElement <> nil do
     begin
       Data1 := Data1.parentElement;
     end;
     memo1.Text := Data1.outerHTML;
                   .. do stuff, working through Memo1, as reqd.
  finally
    Memo1.Free;
  end;
end;

procedure TfMMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
    if WebBrowser <> nil then
      WebBrowser.free;
end;

Open in new window


It all seems to work.

I got the loop (while Data1.parentElement <> nil do begin Data1 := Data1.parentElement;  end;) from somewhere, years ago. I am not sure what it does, but it looks like it is working through the nesting until it gets to the final element.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamDLovellAuthor Commented:
My solution provided the final fix for the problem
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.

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.