I'm working in a code that promise get value from url bar, but now appear one compilation error in some parameters of IAccessible get_accValue property. So, how fix?
Any help will be appreciated!
Here is the my code:
uses
oleacc;
function ffdoc: THandle;
const
A_szClassName: array[0..6] of PChar = ('MozillaUIWindowClass','MozillaWindowClass',
'MozillaWindowClass','MozillaWindowClass','MozillaContentWindowClass',
'MozillaWindowClass','MozillaWindowClass');
var
i: Integer;
begin
Result:= 0;
for i:= 0 to 6 do
Result:= FindWindowEx(Result,THandle(nil),A_szClassName[i],nil);
end;
function ffurl:string;
var
acc: IAccessible;
pw: PWChar;
begin
if AccessibleObjectFromWindow(ffdoc,OBJID_CLIENT,IID_IAccessible,Pointer(acc)) = 0 then
Acc.get_accValue(CHILDID_SELF,pw);
Result:= pw;
end;
If you look at the declaration for oleacc.IAccessible.get_accValue()
, it is apparent why you are getting the error:
function Get_accValue(varChild: OleVariant; out pszValue: WideString): HResult; stdcall;
You are trying to pass a PWChar
where an out WideString
is expected. Delphi is very strict when it comes to var
and out
parameters.
You need to change your pw
variable:
function ffurl:string;
var
acc: IAccessible;
pw: WideString;
begin
if AccessibleObjectFromWindow(ffdoc, OBJID_CLIENT, IID_IAccessible, acc) = 0 then
acc.get_accValue(CHILDID_SELF, pw);
Result := pw;
end;
COM uses BSTR
for its strings, which Delphi wraps with WideString
. So always use WideString
when passing strings in/out of COM interfaces.