Recent

Author Topic: Why Clipboard dont work some times?  (Read 449 times)

rodimus111

  • New member
  • *
  • Posts: 6
Why Clipboard dont work some times?
« on: June 26, 2019, 07:03:30 pm »
I have the next code:

Clipboard.AsText:=inttostr(Random(100));
sleep(33);
RichMemo1.PasteFromClipboard;

I had to put a sleep between parameters, otherwise the 'Paste process' sometimes doesn't work. Is there a way to avoid this problem?
(Im working on windows 10)

Thaddy

  • Hero Member
  • *****
  • Posts: 9288
Re: Why Clipboard dont work some times?
« Reply #1 on: June 26, 2019, 07:11:15 pm »
Windows 10 has a messaging system. You obstruct that with sleep(33). In this case use Application.ProcessMessages instead of the silly sleep, which is blocking.
You will be OK unless you access the clipboard in nano seconds..
You have to give the OS the time to process its message queue. Sleep() is not a very bright idea.... Although under Windows with one! exception: Sleep(0) has special meaning and means relinquish time slice. Any other sleep is bad programming in such a scenario, even sleep(1)....
« Last Edit: June 26, 2019, 07:19:56 pm by Thaddy »
also related to equus asinus.