Kamyar Kimiyabeigi
Kamyar Kimiyabeigi

Reputation: 99

work with WordApplication in delphi7

how can i disable "print" & "print preview" in Microsoft Word with WordApplication (delphi7)?

Upvotes: 1

Views: 918

Answers (1)

Alistair Ward
Alistair Ward

Reputation: 1093

One way is to set up a COM Event Sink and listen for IApplicationEvents2 or IApplicationEvents3. You can respond to DocumentBeforePrint() and set the cancel flag. This should disable printing, but don't know about Print Preview. I have had a bit of a search but haven't found a good reference for doing this from Delphi (but I'm certain it can be done...)

If you were working in VBA, you could also create FilePrint and FilePrintPreview macros to override the default behaviours and disable print functions.

Further Info

Look at the sample \Program Files\Borland\Delphi7\Demos\ActiveX\OleAuto\Word8\word8auto.dpr

This only traps the IApplicationEvents. You will need to extend this to support IApplicationEvents2.

From looking at the code, the required changes are:

  1. Change uses Word97 to Word2000 (or WordXP)
  2. Add new events/properties to TWordEventSink (FOnDocumentBeforePrint, FOnDocumentBeforeSave etc...)
  3. Add new events/properties to TWordObject
  4. Implement new events in TWordEventSink.Invoke. Watch out for extracting/returning parameters
  5. In TWordObject.Create, change ApplicationEvents in the TWordEventSink.Create call to ApplicationEvents2

Upvotes: 1

Related Questions