如下所示,IDISPATCH赋值给variant后可以调用方法(quit)。
program cp4f;
{$APPTYPE CONSOLE}
uses
SysUtils,
variants,
comobj,
activex,
windows ;
var W:variant;
m_s:boolean;
m_s2:widestring;
begin
{ TODO -oUser -cConsole Main : Insert code here }
CoInitialize(nil);
w := CreateOLEObject('Word.Application') ;
Sleep(2000);
// m_s:=w.Visible;
// writeln('Visible:',m_s);
//m_s2:=w.Version;
//writeln('version:',m_s2);
w.quit;
w:=unassigned;
CoUnInitialize;
end.
但是属性访问就没有试验成功。。似乎要用更原始的方式。。
program cp2;
{$APPTYPE CONSOLE}
uses
SysUtils,
variants,comobj,activex,ole2,windows;
var W:IDispatch;
V:String;
theid:Integer;
mv,ppn:widestring;
mres:HRESULT;
ho,VRESULT:VARIANT;
rest :boolean;
myinp:TDispParams=();
begin
CoInitialize(nil);
W:=CreateOleObject('Word.Application');
ppn:='Visible';
mres:=W.getidsofnames(
guid_null,
@ppn,
1,
locale_system_default,
@theid
);
olecheck(mres);
writeln(theid);
mres:= W.Invoke(
theid,
GUID_NULL,
locale_system_default,
DISPATCH_PROPERTYGET,
myinp,
@VRESULT,
nil,
nil
);
olecheck(mres);
rest:=VRESULT;
writeln(rest);
ho:=W;
W:=nil;
ho.quit;
ho:=unassigned;
CoUnInitialize;
end.
您还没有登录,请登录后发表评论(快捷键 Alt+S / Ctrl+Enter)
V:String;
theid:Integer;
mv,ppn:widestring;
mres:HRESULT;
ho,VRESULT:VARIANT;
rest :boolean;
myinp:TDispParams=();
begin
CoInitialize(nil);
W:=CreateOleObject('Word.Application');
ppn:='Visible';
mres:=W.getidsofnames(
guid_null,
@ppn,
1,
locale_system_default,
@theid
);
olecheck(mres);
writeln(theid);
mres:= W.Invoke(
theid,
GUID_NULL,
locale_system_default,
DISPATCH_PROPERTYGET,
myinp,
@VRESULT,
nil,
nil
);
olecheck(mres);
rest:=VRESULT;
writeln(rest);
ho:=W;
W:=nil;
ho.quit;
ho:=unassigned;
CoUnInitialize;
end.
您还没有登录,请登录后发表评论(快捷键 Alt+S / Ctrl+Enter)
uses
SysUtils,
variants,comobj,activex,ole2,windows;
var W:IDispatch;
V:String;
theid:Integer;
mv,ppn:widestring;
mres:HRESULT;
ho,VRESULT:VARIANT;
rest :boolean;
myinp:TDispParams=();
begin
CoInitialize(nil);
W:=CreateOleObject('Word.Application');
ppn:='Visible';
mres:=W.getidsofnames(
guid_null,
@ppn,
1,
locale_system_default,
@theid
);
olecheck(mres);
writeln(theid);
mres:= W.Invoke(
theid,
GUID_NULL,
locale_system_default,
DISPATCH_PROPERTYGET,
myinp,
@VRESULT,
nil,
nil
);
olecheck(mres);
rest:=VRESULT;
writeln(rest);
ho:=W;
W:=nil;
ho.quit;
ho:=unassigned;
CoUnInitialize;
end.
您还没有登录,请登录后发表评论(快捷键 Alt+S / Ctrl+Enter)
V:String;
theid:Integer;
mv,ppn:widestring;
mres:HRESULT;
ho,VRESULT:VARIANT;
rest :boolean;
myinp:TDispParams=();
begin
CoInitialize(nil);
W:=CreateOleObject('Word.Application');
ppn:='Visible';
mres:=W.getidsofnames(
guid_null,
@ppn,
1,
locale_system_default,
@theid
);
olecheck(mres);
writeln(theid);
mres:= W.Invoke(
theid,
GUID_NULL,
locale_system_default,
DISPATCH_PROPERTYGET,
myinp,
@VRESULT,
nil,
nil
);
olecheck(mres);
rest:=VRESULT;
writeln(rest);
ho:=W;
W:=nil;
ho.quit;
ho:=unassigned;
CoUnInitialize;
end.
您还没有登录,请登录后发表评论(快捷键 Alt+S / Ctrl+Enter)
引文来源 freepascal 2.2 发布了, com/ole 兼容性有所提高 - zzsczz - ITeye技术网站