How to pass a parameter to a OLE Automation object such as MS Word

坚强是说给别人听的谎言 提交于 2019-12-12 11:24:42

问题


This is mainly a Delphi syntax related question. I need to set a parameter to True when calling a method of an OLE object.

I need to set in Word Automation (this is from Word Reference):

wdApp.Quit SaveChanges:=wdDoNotSaveChanges

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

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? Thanks.


回答1:


You can write:

Wordapp.Quit(SaveChanges:=wdDoNotSaveChanges);

Or use this:

word := CreateOleObject('Word.Application'); 

.... 
word.DisplayAlerts := false;
word.Quit; 


来源:https://stackoverflow.com/questions/10733158/how-to-pass-a-parameter-to-a-ole-automation-object-such-as-ms-word

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!