Question

I have an issue where in i am trying to retrieve object from clipboard modify it and add it back ...

Time and again I keep getting

requested operation on clipboard could not be performed

Looks like the clipboard is being locked by some process, how do I free the clipboard?

Was it helpful?

Solution

You cannot free it. If another app has the clipboard open, you have to wait until it closes it. If the clipboard has been recently (within the past second or two) modified, you should expect that other apps will be opening it for examination, and therefore should expect failures if you expect to be able to open it immediately yourself. You need to use try..except handlers, along with sleep(), and a "3 strikes" loop.
pseudo code:

Success := false;
Attempts := 0;
While (Attempts < 3) and (Success = false) do
begin
  Try
    inc(Attempts);
    OpenClipboard;
    Success := true;
  except
    sleep(attempts * 1000);
  end
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top