marked-down
marked-down

Reputation: 10418

Turbo Pascal for Windows: Copy output to clipboard?

I'm completing a program in Turbo Pascal 7 for Windows as part of a programming class school project, essentially we've been given a brief and told to go off by ourselves and implement and code the program.

The brief states to create a program where a user can enter a message, select a letter shift, and then each letter will be 'encrypted' according to that shift (essentially ROT13). Easy.

I've got in running in the Turbo Pascal for Windows 7 terminal window, and it outputs the resulting encrypted text:

writeln('Encrypted message is ', line ,' for a shift of ', shift);
readln;

What I'd like to do is extend beyond this by going one step further and allow the user to copy the output (var: line) to their windows clipboard. I've been searching far and wide across the internet for two days now and have yet to come across anything which can help me. I'm now starting to wonder if Pascal even has the ability to do this?

Cheers, Luke.

Upvotes: 2

Views: 2160

Answers (3)

Chris Thornton
Chris Thornton

Reputation: 15817

If you were using Delphi, you could use Clipboard.SetTextBuf(PChar(somestring)); This is how I do it in my Dos2Clip utility, which apparently I made available free back in 2005. I've made the source available at the link below, all 25 lines of it. ;)

In Vista and higher, there is a "clip" command available in batch files or the command line.

ex: echo “hello, world!” | clip

See my writeup here, which has a download link for my Dos2Clip program (with source). I see Clip2Dos is in there too.

http://www.clipboardextender.com/general-clipboard-use/command-window-output-to-clipboard-in-vista

Upvotes: 2

Marco van de Voort
Marco van de Voort

Reputation: 26361

First, is the resulting binary a DOS or win3.x EXE?

If DOS Afaik there are ways to reach the clipboard from dos via INT 2F extensions.

Search in the massive SWAG archive that contains heaps of examples for Turbo Pascal (and -For Windows)

If win3x then

http://www.programmersheaven.com/mb/pasprog/420895/420895/use-of-windows-clipboard/

If this reply sounds very vague, then it is because all this is 20 years ago :-)

Upvotes: 2

LeleDumbo
LeleDumbo

Reputation: 9340

I'm now starting to wonder if Pascal even has the ability to do this?

Yes if you don't use that outdated 20 years old Pascal product. I'm not sure whether it can access the clipboard (since windows clipboard is 32-bit API) or not, but big chance it can't, at least not without hack. Use Free Pascal or Delphi and access Windows API directly to play with clipboard (search MSDN for this).

PS: Clipboard has nothing to do with Pascal as a language. It's simply a concept that the OS has, and it allows programs to use it.

Upvotes: 3

Related Questions