简体   繁体   English

Delphi OLE自动化冻结GUI

[英]Delphi OLE Automation freezing GUI

We are using some OLE automation in Delphi 7 to open a word document, then once loaded, save it, and load it into a database. 我们在Delphi 7中使用了一些OLE自动化功能来打开word文档,然后将其加载,保存并将其加载到数据库中。

This is working fine, but part of the requirement is to have a progress bar whilst the OLE bit is taking place, and also a timeout if the OLE part takes too long. 这工作正常,但是部分要求是在OLE位发生时有一个进度条,并且如果OLE部分花费的时间太长,则还要超时。

Problem we are having is that the entire GUI freezes whilst the OLE is taking place. 我们遇到的问题是,发生OLE时整个GUI会冻结。 The progress bar does nothing, then shoots up right at the end. 进度栏不执行任何操作,然后立即结束。

Any ideas on how we could approach this? 关于如何解决这个问题的任何想法?

I think this is going to be difficult to do cleanly. 我认为这很难做到。 So far as I know, Word automation doesn't give you the opportunity to cancel long running events. 据我所知,Word自动化并没有给您机会取消长时间运行的事件。 It also doesn't notify you of progress. 它还不会通知您进度。

Probably the best that you can do is first of all move the automation into a separate thread. 您可能要做的最好的事情是,首先将自动化转移到一个单独的线程中。 Then throw up a marquee progress bar whilst the long running automation is in progress. 然后,在长时间运行的自动化过程中,抛出一个选取框进度条。 At least that will let the user know that something is happening. 至少那会让用户知道正在发生什么。

As far as cancelling goes, you can let the user cancel from your progress dialog and then have your program continue. 就取消而言,您可以让用户从进度对话框中取消,然后继续执行程序。 You could kill the automation thread, but that would leave Word in a bad state. 您可以杀死自动化线程,但这会使Word处于不良状态。 I'd just let it continue to completion, but then ignore the results. 我只是让它继续完成,然后忽略结果。 From the user's perspective this will meet your goals reasonably well, even if it's a little dirty behind the scenes. 从用户的角度来看,即使它在幕后有点脏,也可以很好地满足您的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM