通过兄弟的实践,发现在FormCreate的阶段,根本无法获得ActiveForm的IOleClientSite接
口,... 考虑及寻找资料中 ... ...
procedure TActiveTest.Button1Click(Sender: TObject);
var
Site: IOleClientSite;
browser: IWebBrowser2;
isp: IServiceProvider;
function ClientSite( obj: IUnknown ): IOleClientSite;
var
Site: IOleClientSite;
OleObj: IOleObject;
begin
if (obj.QueryInterface( IOleObject, OleObj ) = S_OK) and
(OleObj.GetClientSite( Site ) = S_OK) then
Result := Site
else
Result := nil;
end;
begin
// ShowMessage('Dragon P.C. Test ActiveX Form');
Site := ClientSite(Self);
// ~~~~~~~~~~~~~~~~~~~~~在FormCreate调用的时候这个接口Site为nil
if (Site.QueryInterface(IServiceProvider, isp) = S_OK) then
if (isp.QueryService(IWebbrowserApp, IWebbrowser2, browser) = S_OK) then
ShowMessage('Browser URL is := ' + browser.LocationURL);
end;