HTML Dialogbox

This should be straight forward.

I have an HTTP link (www.somewhere.com/etc...) which will return an HTML page full of links and text and pictures. I need to display the page in a dialog box and when the user selects a link with the mouse close the box and return the link.

Anybody got some code along these lines?
LVL 27
BigRatAsked:
Who is Participating?
 
JaccoCommented:
Hi,

That is a pitty. It is just an ActiveX import though. Tweaked a bit. You might be able to import it?

It is an import of C:\WINNT\System32\shdocvw.dll

Regards Jacco
0
 
JaccoCommented:
Hi there,

Here is a unit that does that:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls;

type
  TWebForm = class(TForm)
    Browser: TWebBrowser;
    procedure FormShow(Sender: TObject);
    procedure BrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
    procedure BrowserBeforeNavigate2(Sender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool);
  public
    URL: string;
    Complete: Boolean;
  end;

var
  WebForm: TWebForm;

implementation

{$R *.dfm}

procedure TWebForm.FormShow(Sender: TObject);
begin
  Browser.Navigate(URL);
end;

procedure TWebForm.BrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant);
begin
  Complete := SameText(URL, Self.URL);
end;

procedure TWebForm.BrowserBeforeNavigate2(Sender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool);
begin
  if Complete then
  begin
    Self.URL := URL;
    ModalResult := mrOK;
    Cancel := True;
  end;
end;

end.

!! Be sure to hook up the three events correctly.

You can call this form from another form with the follwong code:

procedure TForm1.Button2Click(Sender: TObject);
begin
  with TWebForm.Create(Self) do
  try
    URL := 'http://www.yahoo.com/';
    ShowModal;
    Memo1.Lines.Add('URL: ' + URL);
  finally
    Free;
  end;
end;

One minor downside of this code is that the URL you start with has to be exactly the same as the one that passes in BrowserDocumentComplete when downloading of the page has finished. I tested with yahoo and it worked.

Regards Jacco


0
 
BigRatAuthor Commented:
Great!!!

But with Delphi 5 Stanard I don't have TWebBrowser :(
0
 
BigRatAuthor Commented:
50 extra cheeses for the import! Thanks.
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.