Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sinking events in EmbeddedWB or WebBrowser

1,019 views
Skip to first unread message

Claude Deschamps

unread,
Jan 10, 2003, 4:47:26 PM1/10/03
to
I'm trying to sink events from an EmbeddedWB or WebBrowser instance in
D5/6.
How can I connect an event (like onSelectStart, or any other by the way)
with my own method?
I know I don't have enough knowledge of COM, I'm trying to learn more about
it, but an working example would be very welcome.

Thanks in advance.

Deborah Pate (TeamB)

unread,
Jan 11, 2003, 6:59:34 AM1/11/03
to
<<Claude Deschamps:

I'm trying to sink events from an EmbeddedWB or WebBrowser
instance in D5/6.
>>

You can assign to the relevant IHTMLDocument2 Link an
IDispatch-implementing object that calls your event in its
Invoke method. Here's a bit of code to get you started:

procedure MyEvent;
begin
ShowMessage('This is an assigned event');
end;

var
Link: IHTMLElement;
OldEvent, NewEvent: OleVariant;
..
Link := Document.Links.Item(0, 0) as IHTMLElement;
OldEvent := Link.Onclick; // so you can restore it later
NewEvent := TEventObject.Create(MyEvent) as IDispatch;
Link.onclick := NewEvent;

type
TEventObject = class(TDebugInterfacedObject, IDispatch)
private
FOnEvent: TProcedure;
protected
function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
public
constructor Create(const OnEvent: TProcedure);
property OnEvent: TProcedure read FOnEvent write FOnEvent;
end;

implementation

uses Windows, ActiveX;

{ TEventObject }

constructor TEventObject.Create(const OnEvent: TProcedure);
begin
inherited Create;
FOnEvent := OnEvent;
end;

function TEventObject.GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
begin
Result := E_NOTIMPL;
end;

function TEventObject.GetTypeInfo(Index, LocaleID: Integer;
out TypeInfo): HResult;
begin
Result := E_NOTIMPL;
end;

function TEventObject.GetTypeInfoCount(out Count: Integer): HResult;
begin
Result := E_NOTIMPL;
end;

function TEventObject.Invoke(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer): HResult;
begin
if (Dispid = DISPID_VALUE) then
begin
if Assigned(FOnEvent) then
FOnEvent;
Result := S_OK;
end
else Result := E_NOTIMPL;
end;

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html


Deborah Pate (TeamB)

unread,
Jan 11, 2003, 7:13:50 AM1/11/03
to
<<Deborah Pate (TeamB):
TEventObject = class(TDebugInterfacedObject, IDispatch)
>>

Oops - take the 'Debug' out of there. :)

Claude Deschamps

unread,
Jan 11, 2003, 11:12:31 AM1/11/03
to
>You can assign to the relevant IHTMLDocument2 Link an
>IDispatch-implementing object that calls your event in its
>Invoke method. Here's a bit of code to get you started:

I was able to adjust to my needs your code and it is working very well,
thanks a lot.

Claude

0 new messages