[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to use WebDispatcher to retrieve data

Posted on 2014-08-28
3
Medium Priority
?
485 Views
Last Modified: 2014-09-25
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?
0
Comment
Question by:GrahamDLovell
  • 2
3 Comments
 
LVL 28

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 2000 total points
ID: 40324973
Look at this blog. Depending on Delphi version - there are few options. Mostly third part.
One is webfmx.
0
 

Accepted Solution

by:
GrahamDLovell earned 0 total points
ID: 40325029
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
 

Author Closing Comment

by:GrahamDLovell
ID: 40343516
My solution provided the final fix for the problem
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

872 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