It doesn't hurt to be a little more cautious. Try this for starters:
{$ASSERTIONS ON} // on top of the unit
procedure TForm1.Button1Click(Sender: TObject);
var
Doc3 : IHTMLDocument3 = nil; // initialize
url:widestring; // use proper type
onull:Olevariant = VarNull; // initialize;
FWebBrowser: IWebBrowser2 = nil;; // initialize
begin
FWebBrowser := CreateComObject(CLASS_InternetExplorer) as IWebBrowser2;
try
Assert(FWebBrowser <> nil,'webrowser not initialized');
url:='http://www.google.com';
FWebBrowser.Navigate(Url, onull, onull, onull, onull);
Sleep(250);
Doc3 := FWebBrowser.Document as IHTMLDocument3; // error occurs here
Assert(Doc3 ><> nil,'Doc3 not initialized');
except
On E:EAssertionFailed do // which of the two?
ShowMessage(e.message)
else
raise; // it is something else;
end;
end;
Not tested.
Also note that the RPC server service needs to be running! It can be turned off.
On my computer I need to start it manually, because I configured the service like that.
Many sysadmins do the same.
Also note maybe that there needs to be a call to coInitialize(nil) and coUnInitialize somewhere in your program and in the context of the main thread.
But usually one of the COM related units do that in initialization/finalization sections.