Recent

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

rodimus111

  • Newbie
  • 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: 14364
  • Sensorship about opinions does not belong here.
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 »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018