[fpc-pascal] CTRL-Break and asynchronous exec

Marco van de Voort marcov at stack.nl
Fri Apr 10 16:48:54 CEST 2009


In our previous episode, Jürgen Hestermann said:
> I am trying to port some console programs to Free-Pascal(they use the 
> CRT unit and originaly where written for Turbo-Pascal then they were 
> ported to Virtual-Pascal). I use "MODE OBJFPC". Now I am stumbling over 
> some problems:
> 
> 1.) I check for keyboard input with the READKEY function. How can I 
> avoid that the key STRG-C stops the program? I want to use this key for 
> the Copy-to-clipboard function. In the manual "CHECKBREAK" is mentioned 
> but there it also says that it's not used (and setting it to FALSE 
> doesn't change anything).

Don't know if there is a generic function to do this. However in such cases
it is easiest to look how FPC's biggest console app (the textmode IDE) does
it.
 
> 2.) Is there a (Free-Pascal) standard function to execute other programs 
> synchronously AND asynchronously (so that there is no need to change 
> this code for different platforms)?

Synchronously: TProcess or ExecuteProcess
Asynchronously: TProcess

> Or do I have to use WinAPI functions 
> like CREATEPROCESS for that? Virtual-Pascal had an EXECFLAGS variable 
> which controlled the behaviour of the EXEC function. Does something 
> similar exist in Free-Pascal?

Do not use the dos.exec function. It has argument and path length problems
(due to shortstrings), use the executeprocess function(s) instead. They are
in sysutils.

And in general, have a look at tprocess:

http://www.freepascal.org/docs-html/fcl/process/index.html
http://www.freepascal.org/docs-html/fcl/process/tprocess.html

and the fcl-process examples (hopefully) installed with your release.
 



More information about the fpc-pascal mailing list