Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You were doing it right. The problem here is that clipboard class doesn't somehow encount to be used in console applications. Your application failed on the following line from the <code>lclintf.inc</code> file, where the <code>WidgetSet</code> object is going to be accessed. That fails because the <code>WidgetSet</code> variable is <code>nil</code> while you're in console application just because console application doesn't need any widgets:</p> <pre><code>function ClipboardRegisterFormat(const AMimeType: string): TClipboardFormat; begin Result := WidgetSet.ClipboardRegisterFormat(AMimeType); end; </code></pre> <p>To workaround this you may add the <code>Interfaces</code> unit to your uses clause and add the <code>LCL</code> package dependency to your project:</p> <pre><code>program Project1; uses Clipbrd, Interfaces; begin Clipboard.AsText := 'Hello, I''m a text from clipboard!'; end. </code></pre> <p>But according to your additional question it seems that you want to make the application, which will just copy certain text to the clipboard and terminates. That's what the console application type is not a right choice because of that console window shown for a short time. For that sort of application I would make the formless window application (please note that I know this trick only from Windows platform):</p> <ol> <li>Create a new application through menu <code>File / New...</code>, select <code>Project / Application</code> in the dialog's tree view and create a new project by clicking <code>OK</code></li> <li>Now let's remove the only unit (with a form) from your project; go to the menu <code>Project / Remove from Project</code> and in the newly opened dialog select <code>unit1.pas</code> and click <code>OK</code></li> <li>Now you have a unitless (and formless) application, so what remains is to write a code to copy the text to the clipboard; so now let's open the project source from menu <code>Project / View Project Source</code> and as the project source paste a code like this (this is the shortest possible form):</li> </ol> <p></p> <pre><code>program Project1; uses Interfaces, Forms, Clipbrd; begin Application.Initialize; Clipboard.AsText := 'Hello, I''m a text from clipboard!'; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload