我正在使用 TWordApplication 处理 MS Word 文件。当用户更改文档时,我需要显示消息,但是当文档为只读时,不应显示消息。
打开只读文档时出现问题,然后用户可以选择查看 - 编辑文档并进行一些更改。在这种情况下,我需要显示消息,但文档的属性 ReadOnly 没有改变。
用户启用编辑文档时如何处理操作?
我没有任何想法,请建议我。
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;