Recent

Author Topic: OLE connection issue  (Read 934 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
OLE connection issue
« on: September 21, 2019, 06:32:53 am »
Hi,

I'm working with PowerPoint and I've got some code which copies a slide from one presentation and parts it into another. This works fine in VBA but in Pascal I often, but not always get an error message saying that the clipboard is empty. The paste command comes straight after the copy, but if I put a sleep 1500 in between, it's slow, but works.

I know from other languages and use of connections that I had to wait for the connection command to complete before going on to the next command and I'm thinking this might be the case here to.

Does anyone have any thoughts on this, and if it is likely to be this then how would I wait for the copy command to complete?

Many thanks
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: OLE connection issue
« Reply #1 on: September 21, 2019, 06:27:52 pm »
Try putting some Application.ProcessMessages and Sleep(0) between strokes.
The only true wisdom is knowing you know nothing

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: OLE connection issue
« Reply #2 on: September 26, 2019, 03:15:36 am »
Thanks Jamie, I assume you mean adding the sleep as a PowerPoint command not a native Pascal command.
However, this approach is pretty much the same as what I've done as a workaround, ie simply put Pascal to sleep between the copy and the paste. Tht works, but isn't very optimal.
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: OLE connection issue
« Reply #3 on: September 26, 2019, 10:45:25 pm »
Sleep(0) does not cause a time delay, what it does is switches out the task and then comes back, during that time the OS should have time to process what it needs to complete the job.

 SLeep(0) is very common in Threads too.

 I don't know how it behaves on other targets but I've used that in threads for windows to force the thread to switch out at that point and allow others to process.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018