Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

Clipboard Viewer Component Example

Applies to: ~>2.0

The following is an example of how to use the Clipboard Viewer Component.

Drop a TPJCBViewer component, a TButton and a TMemo on a form. Do not change any of the components’ default properties. Add the Clipbrd unit to your uses clause. Using the object inspector, create the following event handlers:

Implement the event handlers as follows:

procedure TForm1.PJCBViewer1ClipboardChanged(Sender: TObject);
  // Clipboard has changed - emit beep and decide whether to enable button
  // (only if text is on clipboard)
  Button1.Enabled := ClipBoard.HasFormat(CF_TEXT);

procedure TForm1.Button1Click(Sender: TObject);
  // We assume this button can only be clicked when there is text on clipboard,
  // so it is safe to display the text
  Memo1.Text := ClipBoard.AsText;

Because TPJCBViewer’s TriggerOnCreation property is True by default, an OnClipboardChanged event is triggered as the program starts. The beep that is generated by the event handler proves this.

The button is enabled only if the clipboard contains text and becomes greyed out when the clipboard doesn’t contain text. Clicking the button displays the clipboard text in the memo. Whenever the clipboard’s contents change a beep is emitted.