Jump to content

Mark Williams

Members
  • Content Count

    168
  • Joined

  • Last visited

Community Reputation

11 Good

Technical Information

  • Delphi-Version
    Delphi 10.3 Rio

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I am automating Word via TWordApplication. I would like to create the word document in its own unique instance of Word. It is possible to open the document in its own instance by setting the ConnectKind to ckNewInstance, but Word is then a bit of a bandit and if the user open a new word document other than via my app my word instance gets hijacked by the new Word document. It doesn't sound like such a big problem, but these are some of the consequences: If the pirate document enters modal mode so does my document and my app can't do anything with it. Of course, if the user puts my document into modal mode I have the same issue and I have to respond to OLEExceptions for rejected calls. But in he case of my own document I can pop up it up from my app for the user to deal with the modal dialog before proceeding. If it is a pirate document (and there could well be more than one) it is a bit yuk to tell the user to either find it themselves and kill the modal dialog or to pop up all possible docs that might be modal. Even worse than this is that if the user opens a blank document via my exe and then open an existing word document not via my app Word commits high sea piracy and hijacks my blank document completely so that unless I monitor this my app is dealing with the wrong document altogether. There is a registry hack to force Word to open in a new instance every time, but I don't want to force that on users, plus I think it requires admin privileges. In the absence of a ckUniqueInstance constant I have been trying to replicate that effect by monitoring the onDocumentChange event of the Word application and checking if the application's documents count goes above 1. If so I close the pirate document and re-open it in its own instance. I appreciate this is not perhaps the most elegant solution and I also suspect I am going to be told not to interfere with the user experience in this way. I having quite made my mind up as yet. But it almost works, subject to two issues (so far) one major, one minor and I am curious to see if I can get it to work. First, when my app opens a new blank document I add a custom variable to the document simply so that it is flagged as having content. This stops Word trying to hijack the document when an existing document is subsequently opened. Doc.Variables.Add('AnyOldRubbish', 1); //this flags the document as having content And then in the DocumentChange event: procedure TForm.DocumentChange(ASender: TObject); var i : integer; WordAppT : TWordApplication; Template, FileName : OleVariant; begin if wordApp.Documents.Count>1 then begin for i:=WordApp.Documents.Count downTo 1 do begin Template := EmptyParam; if WordApp.Documents.Item(i) <> Doc then begin FileName := WordApp.Documents.Item(i).FullName; if not FileExists(FileName) then FileName := ''; Template := WordApp.Documents.Item(i).Get_AttachedTemplate; if Uppercase(Template) = 'NORMAL.DOTM' then Template := EmptyParam; //Close the offending document! WordApp.Documents.Item(i).Close(false, emptyParam, emptyParam); {PROBLEM CODE - see below} //Reopen it in a separate instance of Word WordAppT := TWordApplication.Create(Nil); WordAppT.ConnectKind := ckNewInstance; if FileName<>'' then WordAppT.Documents.open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam) else WordAppT.Documents.Add(EmptyParam, EmptyParam, EmptyParam, True); WordAppT.Visible := true; WordAPPT.ActiveWindow.Activate; end; end; end; end; The two problems: By adding the variable I am marking blank documents as having been changed when they should be marked as unchanged. Not a major problem. Would be good not to have to do this, but if I can solve problem 2 I can deal with this issue by checking the word count property of the document to see if there has been any substantive change, Not perfec, but good enough for my purposes. The above code works neatly when the user tries to open a blank pirate document, but not when they try to open an existing document. In the latter case, whilst the pirate document does get opened in its own new instance, the closing it in the first place causes my original document to become unresponsive and I can't for the life of me work out why. If I break the process down into separate chunks it works fine: Open my document. Open an offending existing document outside of my app. Add a button to close the offending document. Add another button to reopen the offending document. This works leading me to believe it might be a timing issue. So I tried adding a sleep before and after the call to close the pirate document, but made no difference.
  2. Mark Williams

    Problems installing 10.3.3

    Has anyone had problems installing 10.3.3 via the web installer. It keeps failing on me some way through the process saying it can't unzip a file. I have a partial installation, but only 32bit. I also have no idea what's missing. I have tried installing both 32 bit and 64 bit windows versions. I have also tried installing just 64 bit, but that also fails during process.
  3. Mark Williams

    64bit Out of Process Server

    OK. That's good to know. Thanks.
  4. Mark Williams

    64bit Out of Process Server

    Yes. But it didn't create the Delphi wrapper that you get via the type library functions in the IDE
  5. Mark Williams

    64bit Out of Process Server

    There is a registry hack to get around this: https://www.codeproject.com/questions/267099/how-do-i-use-32-bit-dll-in-64-bit-app
  6. Mark Williams

    64bit Out of Process Server

    Apologies duplicate post.
  7. Mark Williams

    64bit Out of Process Server

    I have worked out how to import the type library for a 64bit out of process server using tlibimp.exe. I was originally pointing tlibimp at the exe file and hoping it would magically produce something for me. It needs to be pointed at the tlb file.
  8. Mark Williams

    64bit Out of Process Server

    I guess so.
  9. Mark Williams

    64bit Out of Process Server

    Thanks for the tip. I will look into it if I have problems via com. My out of process server is only intended for (and will only work with) a Word Add-In that I am developing. So I may run into problems with 32 bit via 64 bit if users are running 32 bit word. So that's something I'm going to have to overcome.
  10. Mark Williams

    64bit Out of Process Server

    Thanks that worked. I originally just ran my app from a shortcut with the /regserver parameter, but that didn't seem to work ie no entries in the register. Running it through the IDE with /regserver did the job. However, how do I import this type library into Delphi? As I mention above it is 64 bit and therefore you can't do it via the IDE so I have tried with tlibimp.exe via a cmd prompt. It still report an error loading the type library.
  11. I have converted an existing 64bit app into an out of process com server by adding an automation object, but now I am completely lost as to how to register it and how to import the type library. RegSvr32 fails with "DLLRegisterServer" not found. I have tried running with "/regserver" switch. In non admin mode it crashes and in admin mode it asks if you want to make changes etc, but then doesn't seem to run the app (no sign of it in processes) although no error appears. I tried using tlibimp.exe to import the type library, but that reported an error loading the type library. I assume that is because there is no type library to import on account of the failure to register the server in the first place!
  12. Mark Williams

    TIDHTTP -v- THTTPCLient

    The post seems to mention a fix, but I haven't tried it. I have an old Windows 7 machine here somewhere and will check it out. However, since Windows 7 is no longer supported and, presumably, no longer secure to use and my app has to be run in a secure environment, it is probably okay for me to say that Windows 7 is not supported.
  13. Mark Williams

    TIDHTTP -v- THTTPCLient

    I'm doing a lot more than polling an url, but I don't appear to be having any issues with THTTPClient and it is pretty simple to set up and use and it doesn't need OpenSSL, I personally can't see any particular reason to switch to Indy. although it would be pretty simple to do so, I was just wondering if there were any known issues/frailties with THTTPClient that would provide an imperative for switching to Indy.
  14. Mark Williams

    Switching TLS on/off on Server

    Researching a little more thoroughly, I've come to the conclusion that this is probably not a good idea for security reasons.
  15. I am configuring my server (TWebModule) to dispense with TLS where the request is from a machine on a local network. To do this I am checking the following properties of TWebRequest: ServerPort - to see if the request has come in on 443 If not 443 then RemoteAddr - to see if the ip address of the requestee falls within the private ranges: 10.0.0.0 - 10.255.255.255 172.16.0.0 - 172.31.255.255 192.168.0.0 - 192.168.255.255 If it doesn't reject the request and ask it to be made over http. Is this a sound approach? Are there any dangers I should be aware of? If this is a sound approach I assume I should add a config files to specify the permitted ip ranges so that it could include private networks that fall out
×