Lazarus

Programming => General => Topic started by: daveinhull on September 21, 2019, 06:32:53 am

Title: OLE connection issue
Post by: daveinhull 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
Title: Re: OLE connection issue
Post by: jamie on September 21, 2019, 06:27:52 pm
Try putting some Application.ProcessMessages and Sleep(0) between strokes.
Title: Re: OLE connection issue
Post by: daveinhull 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
Title: Re: OLE connection issue
Post by: jamie 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.
TinyPortal © 2005-2018