0

I'm working with MS Word files use TWordApplication. I need show message when document was changed by user, but when document is ReadOnly then message shouldn't be show.

I have problem when open readonly document and then user can select View - Edit document and made some changes. In this case I need to show message but property ReadOnly of document did not change.

How can I handle action when user enable edit the document?

I haven't any idea, please suggest me.

var 
  LWordApp: TWordApplication; 
  LWordDoc: _Document;
  LProtectionType: TOleEnum;
begin
  LWordApp:= TWordApplication.Create( nil );
  LWordApp.OnQuit := DocumentClose;
  LWordApp.Connect;
  ...
  LWordDoc:= LWordApp.Documents.Open(АFileName,   // FileName
                                     EmptyParam, // ConfirmConversion
                                     EmptyParam, // ReadOnly
                                     EmptyParam, // AddToRecentFiles
                                     EmptyParam, // PasswordDocument
                                     EmptyParam, // PasswordTemplate
                                     EmptyParam, // Revert
                                     EmptyParam, // WritePasswordDocument
                                     EmptyParam, // WritePasswordTemplate
                                     EmptyParam,  // Format
                                     EmptyParam,
                                     EmptyParam
                                    );
  LProtectionType := LWordDoc.ProtectionType;
  if AProtectionPassword <> '' then
  begin
    if LProtectionType <> wdNoProtection then
      Doc.Unprotect(AProtectionPassword);
  end;
  LWordApp.Visible := True;
  LWordDoc.Close(tmpSaveIT, EmptyParam, EmptyParam);
  LWordApp.Disconnect;
  LWordApp.Quit;
end;

procedure DocumentClose(Sender: TObject);
begin
  ShowMessage("Hello");
end;
Huilo
  • 1
  • I'm afraid I don't find your q at all clear. When **exactly** do you want your message to be shown? F.i. suppose the user starts typing, then closes the document without saving. When would you show the message, and how many times, each time they press a key or what? – MartynA Oct 02 '15 at 12:32
  • Surely whether the document is read-only is irrelevant? You want to show the message if the document has changed, regardless. – Dsm Oct 02 '15 at 14:56

1 Answers1

0

ReadOnly is for specifying that you will open the document as, well, read only. It is not an indicator of the current document.