I'm trying to access the already-running instance of Internet Explorer
Using the routines listed above -
and it does'nt work.
here's my code :
procedure TForm1.FlatButton1Click(Sender: TObject);
var
unk: IUnknown;
di: IDispatch;
inst: IWebBrowser2;
begin
GetActiveObject(CLASS_InternetExplorer, nil, Unk);
Inst:= Unk as Iwebbrowser2;
// Unk stays nil
di:= GetActiveOleObject('InternetExplorer.Application');
// the code raises an OleException
inst:= di as IWebBrowser2;
end;
I find this phenomenon rather strage, since the same code worked on Word and
Excel.
I used the constant CLASS_InternetExplorer based on what's in the type
library,
and tried using the Original GUID from the registry - still with no success.
I even tried using other constants, such as CLASS_WebBrowser_V1 and
CLASS_WebBrowser, and that didn't work either.
Ideas?
thanks,
Victor.
IE doesn't register itself in the running object table, so
GetActiveObject doesn't work. You can use the IShellWindows interface to
get a running instance:
function GetRunningInstance: IWebBrowser2;
var
ShWindows: IShellWindows;
i: integer;
begin
ShWindows := CoShellWindows.Create;
for i := 0 to ShWindows.Count - 1 do
begin
Result := ShWindows.Item(i) as IWebBrowser2;
if Result.LocationURL =
'http://www.djpate.freeserve.co.uk/' then
Break;
end;
end;
--
Deborah Pate (TeamB)
http://delphi-jedi.org
Sorry, no email please.