简体   繁体   English

如何将参数传递给OLE自动化对象,如MS Word

[英]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.

相关问题 MS Word Ole Automation,ADO和外来字符 - MS Word Ole Automation, ADO and foreign characters Delphi单词自动化:在Dll中创建Ole对象 - Delphi word automation: Create Ole Object inside Dll OLE自动化:如何检查变量是否引用了自动化对象 - OLE automation: How to check if a variant references an automation object 使用OLE在MS Word中打印一系列页面(Imprimir em ole对象(word应用程序)com delphi) - Printing a range of pages in MS Word using OLE (Imprimir em ole object (word application) com delphi) delphi如何在word ole自动化中插入换行符(下面的边框) - delphi how to insert line break (border below) in word ole automation 如何在Delphi的OLE自动化过程中使Word不可见 - How to make Word invisible during OLE automation from Delphi 如何通过Delphi中的Ole更改MS Word拼写检查语言? - How to change MS Word spelling check language through Ole in Delphi? OLE自动化:如何在不使用剪贴板的情况下在Word文档之间复制文本 - OLE Automation: How do i copy text between Word documents without using the clipboard 通过自动化在MS Word中设置正确的打印机 - Setting correct printer in MS Word through automation 在没有Word Automation的情况下,在Delphi中读取/解析/修改MS Word文档 - Read/Parse/Modify MS Word document in Delphi without Word Automation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM