[英]How to pass a parameter to a OLE Automation object such as MS Word
This is mainly a Delphi syntax related question. 这主要是与Delphi语法相关的问题。 I need to set a parameter to True when calling a method of an OLE object. 我需要在调用OLE对象的方法时将参数设置为True。
I need to set in Word Automation (this is from Word Reference ): 我需要在Word Automation中设置(这是来自Word Reference ):
wdApp.Quit SaveChanges:=wdDoNotSaveChanges
As an example a dummy procedure where I would like to do this follows (please note WordApp.Quit!): 作为一个例子我想做的虚拟程序(请注意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
Important: instead of using 重要提示:而不是使用
// this is from Word Reference
wdApp.Quit SaveChanges:=wdDoNotSaveChanges
it is possible to use 可以使用
// from Word Reference
wdApp.NormalTemplate.Saved = True
Could anyone please modify my GetWordVersion procedure above so that either one of the 2 approaches above are used? 任何人都可以修改我上面的GetWordVersion程序,以便使用上述两种方法中的任何一种吗? Thanks. 谢谢。
You can write: 你可以写:
Wordapp.Quit(SaveChanges:=wdDoNotSaveChanges); Wordapp.Quit(调用SaveChanges:= wdDoNotSaveChanges);
Or use this: 或者用这个:
word := CreateOleObject('Word.Application');
....
word.DisplayAlerts := false;
word.Quit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.