如何将参数传递给OLE自动化对象(如MS Word) [英] How to pass a parameter to a OLE Automation object such as MS Word
问题描述
这主要是与Delphi语法相关的问题.调用OLE对象的方法时,我需要将参数设置为True.
This is mainly a Delphi syntax related question. I need to set a parameter to True when calling a method of an OLE object.
我需要在Word Automation中进行设置(这是从 Word参考 ):
I need to set in Word Automation (this is from Word Reference):
wdApp.Quit SaveChanges:=wdDoNotSaveChanges
下面是一个我要在其中执行此操作的虚拟过程的示例(请注意WordApp.Quit!):
As an example a dummy procedure where I would like to do this follows (please note WordApp.Quit!):
Procedure GetWordVersion;
var
WordApp: OLEVariant;
begin
{ Create the OLE Object }
Try
WordApp := CreateOLEObject('Word.Application');
WordVersion := WordApp.version;
WordApp.Quit; // >-- HERE!!!!
except
on E: Exception do
begin
WordVersion := -1;
end;
End;
end;
此处(检查接受的答案)相同事情似乎已经完成,但是如果我尝试的话:不会编译.我仅在此处复制相关部分:
Here (check the accepted answer) the same thing seems to be done, but if I try it it:doesn't compile. I copy here only the relevant parts:
Const wdDoNotSaveChanges = 0
[...]
wdo.Quit wdDoNotSaveChanges
[...]
End Function
重要: 而不是使用
// this is from Word Reference
wdApp.Quit SaveChanges:=wdDoNotSaveChanges
可以使用
// from Word Reference
wdApp.NormalTemplate.Saved = True
任何人都可以修改上面的GetWordVersion过程,以便使用上述两种方法之一吗?谢谢.
Could anyone please modify my GetWordVersion procedure above so that either one of the 2 approaches above are used? Thanks.
推荐答案
您可以编写:
Wordapp.Quit(SaveChanges:= wdDoNotSaveChanges);
Wordapp.Quit(SaveChanges:=wdDoNotSaveChanges);
或使用此:
word := CreateOleObject('Word.Application');
....
word.DisplayAlerts := false;
word.Quit;
这篇关于如何将参数传递给OLE自动化对象(如MS Word)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!