2

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.

STT LCU
  • 4,348
  • 4
  • 29
  • 47
marked-down
  • 9,958
  • 22
  • 87
  • 150
  • @Embarcadero: **Send free RAD Studio dvd's to that school NOW**, and make sure that it's not a the crippled version without a commandline compiler. – Wouter van Nifterick Mar 02 '12 at 10:18
  • Many schools use old versions because introducing students to the IDE and the subsequent play of the student with each and every feature and icon takes up too much time. Old versions are simpler and don't attract as much play as a drag-and-drop designer. So in short, it is not the lack of modern tools, but their complexity that is the problem. When I was at fairs for FPC/Lazarus advocacy, there was a serious demand from teachers for a cut down version specialized for educational purposes. – Marco van de Voort Mar 02 '12 at 10:38
  • Still, even if it's not used during the classes, schools where pascal is still being taught are a good place to harvest new Delphi/Lazarus users. It should be promoted there. At school we only used Turbo Pascal, and fellow students showed me how to apply the same knowledge to build cooler stuff with Delphi. We all used illegal copies (booo!), but over the years we've bought many licenses via our employers. If Borland had a better copy protection back then, I definitely wouldn't be writing anything pascal nowadays. – Wouter van Nifterick Mar 02 '12 at 11:38

3 Answers3

3

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.

LeleDumbo
  • 9,192
  • 4
  • 24
  • 38
  • Yep - we've been told to use the ancient Turbo Pascal 7 for Windows (by Borland Software). Getting it to simply work on my windows 7 x64 laptop was a nightmare. – marked-down Mar 02 '12 at 07:07
  • On x64 you would have needed a special emulator, e.g. dos box – David Heffernan Mar 02 '12 at 10:50
  • @MarcovandeVoort: same here, I thought win64 only provides 32-bit compatibility layer – LeleDumbo Mar 02 '12 at 13:26
  • David: I know, but I never knew that clipboard worked in dosbox. – Marco van de Voort Mar 03 '12 at 01:08
  • TP7W did produce Windows executables. I used it for about a year before Delphi appeared and still have the Tom Swan programming book. There should be no problem accessing the clipboard using API functions. I might even look up 'clipboard' in the Swan book when I get home. – No'am Newman Nov 21 '12 at 13:25
2

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 :-)

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
2

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

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62