WebBrowser nie ma właściwości UserAgent nawet pod Delphi XE5. Przecież napisałem że trzeba dodać tą właściwość nie rozumiesz artykułu? Masz cały przykładowy unit działający na Delphi 7:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, ActiveX, StdCtrls;
const
DISPID_AMBIENT_USERAGENT = -5513;
type
TWebBrowser = class (SHDocVw.TWebbrowser, IDispatch)
private
FUserAgent: string;
procedure SetUserAgent (const Value: string);
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HRESULT; stdcall;
public
property UserAgent: string read FUserAgent write SetUserAgent;
constructor Create(AOwner: TComponent); override;
end;
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TWebBrowser.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FUserAgent:='';
end;
function TWebBrowser.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HRESULT;
begin
//check if the DISPID_AMBIENT_USERAGENT flag is being processed and if the User Agent to set is not empty
if (FUserAgent <> '') and (Flags and DISPATCH_PROPERTYGET <> 0) and Assigned(VarResult) and (DispId=DISPID_AMBIENT_USERAGENT) then
begin
//set the user agent
POleVariant(VarResult)^:= FUserAgent+#13#10;
Result := S_OK; //return S_OK
end
else
Result := inherited Invoke(DispID, IID, LocaleID, Flags, Params, VarResult, ExcepInfo, ArgErr); //call the default Invoke method
end;
procedure TWebBrowser.SetUserAgent(const Value: string);
var
Control: IOleControl;
begin
FUserAgent := Value;
//the current interface supports IOleControl?
if DefaultInterface.QueryInterface(IOleControl, Control) = 0 then
Control.OnAmbientPropertyChange(DISPID_AMBIENT_USERAGENT); //call the OnAmbientPropertyChange event
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://whatsmyuseragent.com/'); //tu otwieramy strone jaka chcemy :)
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.UserAgent:= 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0'; //zmiana user agent (jak dodać właściwość UserAgent do WebBrowser jest we wspomnianym artykule)
WebBrowser1.Navigate('about:blank'); //"lewe" navigate
end;
end.