Entries in clipboard (1)


Apesuite Spotlight: Enhanced Firemonkey Clipboard

I just wanted to give you another preview of a new feature coming to Apesuite Beta 6.  

We had a lot of people complaining that our Grid Demo did not behave correctly when cut/copy/paste between applications such as Word and Excel.  We decided that due to the similarity of our component to applications like Excel and Numbers that this complaint would not be going away any time soon and that we should take a few extra hours to improve on our inter-application clipboard functionality.

Unfortunately, Firemonkey has a very simplistic interface that allows only a single string token to be saved to and retrieved from the clipboard.  This wasn't going to work for us as we need to store multiple formats to the clipboard.  To realistically handle most scenarios, we'd have to at least store tab delimited text for excel/numbers, rtf text for ms word, html for various html editors and browsers and of course, our internal copy and paste format that is respective of all metadata that would need to be replicated with the transaction.  

Our answer to this problem was to write our own system crossplatform clipboard object that works on multiple types of data and data formats and allows a clipboard that holds multiple formats at the same time.  

The functionality can be found via a global Clipboard funciton in the "Ape.System.Clipboard" unit. Here's a quick overview of how you can utilize this new feature:

Before adding anything to the clipboard you will want to make sure that there isn't anything else there:


Then add some text to the clipboard by setting the Text property:

Clipboard.Text := 'This is my text';

Now if you want to add that same text with some HTML tags:

Clipboard.HTML := 'This is <b>my</b> text';

And say you had an image of your text that you also wanted to make available for a paint program:

Clipboard.PNG := MyImage.Bitmap;

Clipboard.TIFF := MyImage.Bitmap;

Now on the flipside, say you want to use consume items from the system clipboard.  To pull the text as a string:

str := Clipboard.Text;

or to grab your image back from clipboard:

if Clipboard.HasPNG then

  bmp := Clipboard.PNG;






One of the most important aspects of clipboard usage is being able to define your own format.  We allow you to do this with the TypedText and TypedData properties:

Clipboard.TypedText['myformat'] := 'My|custom|format';

Clipboard.TypedData['myBinaryFormat'] := MyStream;

Of course, all of this is intended to work in both Windows and OS X.  

This new Clipboard functionality should open you up to coding more like a first class citizen of the operating system.  Please give this a try when you get your hands on Beta 6 and let us know what you think.