HOME - - - - - Lazarus Tutorials TOC - - - - - - Other material for programmers
Delicious.Com Bookmark this on Delicious     StumbleUpon.Com Recommend to StumbleUpon

Copy to clipboard / Paste from clipboard

This has good information, and a search button at the bottom of the page

Please don't dismiss it because it isn't full of graphics, scripts, cookies, etc!

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is more fully explained, and there's another tip, at my Power Browsing page.)

This is a sketch of something I hope to finish one day, but in the meantime, "the heart" of a useful technique is here for you. Most tutorials in this series are more extensive. I would like to thank the authors of http://delphi.about.com/od/vclusing/a/tclipboard.htm for reminding me how you make a Delphi program copy to the system clipboard. The page you are reading was worked up from what's there. It is also unusual in my Lazarus tutorials collection for being relatively short.

I've tested what follows in Lazarus. I know something very similar is available in Delphi; it may well use exactly the same syntax.

I will show you how to...

I must remember to finish this tutorial for you.
I must remember to finish this tutorial for you.
I must remember to finish this tutorial for you.
I must remember to finish this tutorial for you.
I must remember to finish this tutorial for you.
I must remember to finish this tutorial for you.

I hope you know exactly how I wrote the above. Copying and pasting to and from the "clipboard" is not just about being lazy. It is a very useful help when generating program code. Typos are avoided. You have an extra incentive to use consistent approaches. In the early 80's, I taught a gifted 12 year old, and he did an amazing amount of his work with the BBC Micro's early "copy/paste" tool. At the time, I though he overdid it. Now I'm a convert.

We all (I hope) use copy/paste from the keyboard. What about within your programs?

I have written a Lazarus application which generates values for the key field of a database. When it generates a new value, it also copies that value to the clipboard. I the merely click on the right edit box on the database's record entry window, and do ctrl-V to paste the application-generated value into the database record. "All" I've saved you is a "select that" and a ctrl-C... but, "try it; you'll like it..." applies!

How to copy something to the clipboard from inside Lazarus or Delphi

Put Clipbrd in the "Uses" clause.

Once that's there, you can do...

Clipboard.AsText:=('Send these words');

...without further ado.

If you were using an application which had executed that command, if you then did ctrl-V (Or invoked a "paste" by any of the other methods) you would get "Send these words" pasted into the currently active control.

You can of course put other things, including variables, inside the brackets, e.g....

sTmp:='Yada, yada';

Two details: The object can ONLY be called "Clipboard". You do not need to "create" or "free" it.

How to copy something to the clipboard from inside Lazarus or Delphi

If you haven't already done so, put Clipbrd in the "Uses" clause.

Once that's there, you can paste from the clipboard (almost) the same way as you copied to it. You don't even need a new function! Just a new syntax. Assuming that your Lazarus (Delphi) form already has a label named "laLabel" on it, to paste what's in the clipboard to the caption of that label, you just use....


... Simples!

To recap:

            powered by FreeFind
  Site search Web search
Site Map    What's New    Search This search merely looks for the words you enter. It won't answer "Where can I download InpOut32?"

If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service. They offer things for the beginner and the corporation.www.1and1.com icon

Ad from page's editor: Yes.. I do enjoy compiling these things for you. I hope they are helpful. However... this doesn't pay my bills!!! Sheepdog Software (tm) is supposed to help do that, so if you found this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page
How to contact the editor of this page, Tom Boyd

Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes. There were two "unknown attributes" in Google+ button code. Sigh.

If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....