title: Why I get "Cannot open clipboard" error?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1859102/how-can-i-fix-cannot-open-clipboard-access-denied-errors">How can I fix &ldquo;Cannot open clipboard: Access Denied&rdquo; errors?</a>  </p>
  </blockquote>
  
  
  
  <p>Hi.</p>
  
  <p>From time to time I get a "Cannot open clipboard" error when I try to do something like this:</p>
  
  <pre><code>procedure TForm1.btnCopyClick(Sender: TObject);
  begin
    Clipbrd.Clipboard.AsText:= Memo.Text;
  end;
  </code></pre>
  
  <p>Any ideas why I get this error?</p>
  
  <p>EDIT:</p>
  
  <p>I have found this possible solution:</p>
  
  <pre><code>procedure StrToClipbrd(StrValue: string);
  VAR hMem: THandle;
      pMem: PChar;
  begin
   hMem := GlobalAlloc(GHND or GMEM_SHARE, Length(StrValue) + 1);
   if hMem &lt;&gt; 0 then
    begin
     pMem := GlobalLock(hMem);
     if pMem &lt;&gt; nil then
      begin
       StrPCopy(pMem, StrValue);
       GlobalUnlock(hMem);
       if OpenClipboard(0) then
        begin
         EmptyClipboard;
         SetClipboardData(CF_TEXT, hMem);
         CloseClipboard;
        end
       else GlobalFree(hMem);
      end
     else GlobalFree(hMem);
    end;
  end;
  </code></pre>
  
  <hr>
  
  <p>Delphi 7, Win xp</p>