Thanks in advance.
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
Oops - take the 'Debug' out of there. :)
I was able to adjust to my needs your code and it is working very well,
thanks a lot.
Claude