问题
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