Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to create event handler without a visible object

Posted on 2009-04-29
5
Medium Priority
?
1,203 Views
Last Modified: 2013-11-23
I have a TWebBrowser, and I want to make it and destroy it as I need it (within same function) but I still want the OnNavComplete event handler to fire off...

is this possible and how?
0
Comment
Question by:kthxbai2u
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
atul_parmar earned 2000 total points
ID: 24269452
Hi,

The following will work.

Atul
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure WebBrowserNavigateComplete2(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.WebBrowserNavigateComplete2(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
  ShowMessage('Navigation Complete');
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  with TWebBrowser.Create(self) do
  begin
    try
      OnNavigateComplete2 := WebBrowserNavigateComplete2
    finally
    end;
  end;
end;
 
end.

Open in new window

0
 
LVL 10

Assisted Solution

by:atul_parmar
atul_parmar earned 2000 total points
ID: 24269460
Oops! failed to destroy the browser

procedure TForm1.Button1Click(Sender: TObject);
begin
  with TWebBrowser.Create(self) do
  begin
    try
      OnNavigateComplete2 := WebBrowserNavigateComplete2
    finally
      Free;
    end;
  end;
end;
0
 

Author Comment

by:kthxbai2u
ID: 24275361
Oh sweet, i didn't know how you set the event handlers, and I couldn't find where Delphi hides them!

This solves ALL of my problems!

Thanks A Million!
0
 

Author Closing Comment

by:kthxbai2u
ID: 31576226
thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Screencast - Getting to Know the Pipeline

571 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