Open word file through delphi

2

I have a system that integrates with MS-Word I can do almost everything in it, just can not open the document and leave it as read-only so that the user can not make modifications. Currently my code looks like this:

//Cria objeto principal de controle
try
  with OleContainer do
  begin
    if OleObjectInterface <> Nil then
    begin
      DestroyObject;
    end;
    //Nome do arquivo usado para abrir o arquivo de entrevista
    vNomeArquivo  := DM.tbParamPASTA_BD.AsString+'\MODELOS\'+DM2.qryConsultasMODELO.AsString;   
    try
      OleContainer.CreateObjectFromFile(vNomeArquivo, OF_READ);
      OleContainer.DoVerb(ovShow);
      Perform(WM_LBUTTONDBLCLK, MK_LBUTTON, 0);
    except
      //Fechar o arquivo
      DestroyObject;
    end;
  end;
finally
  Screen.Cursor := crDefault;
  OleContainer.TabStop := False;

end;

  

PS: I do not want to open a document that has the ReadOnly attribute   I want to prevent the user from changing the document type Protected mode   Unrestricted

    
asked by anonymous 25.05.2018 / 22:25

1 answer

2

We do not use much olecontainer , but for our needs here when we need to leave the document readonly to the user we use the following line ..:

OleContainer.CreateObjectFromFile(vNomeArquivo, false);
OleContainer.DoVerb(ovShow);
OleContainer.OleObject.Protect(3);
Perform(WM_LBUTTONDBLCLK, MK_LBUTTON, 0);
    
29.05.2018 / 12:41