Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-06

ExitProc

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Carsten Bager

If I compile and run my example program and then press Crtl+C the program terminates. I would expect that it terminate by calling "CloseServer" procedure, but it dos not. If the program terminates normally (time runs out) the "CloseServer" procedure is called as expected.

Have I misunderstood something about the ExitProc.

Regards Carsten

program exitp;
Uses sysutils;    {System}
var
  ExitProcGem:pointer;
Procedure CloseServer;
Begin
  ExitProc:=ExitProcGem;
  WriteLn('Server closed.');
End;
begin
  ExitProcGem:=ExitProc;
  ;
  sleep(10000);
  WriteLn('--Close--');
end.

Reply by email

Jonas Maebe
to Carsten Bager
Carsten Bager wrote 7 lines
If I compile and run my example program and then press Crtl+C the program terminates. I would expect that it terminate by calling "CloseServer" procedure, but it dos not. If the program terminates normally (time runs out) the "CloseServer" procedure is called as expected. Have I misunderstood something about the ExitProc.

ExitProc is only called if your program exits via the RTL. This is the case when the program exits normally, or when a run time error or unhandled exception occurs.

ctrl-c is not caught by the FPC RTL. This means it is handled by the operating system, and the default action of the operating system is to simply terminate the process. The FPC RTL therefore does not get any chance to call your exitproc.

I don't know whether there's a platform-independent way in the RTL to turn on the catching of ctrl-c (and converting it to an exception or run time error).

Jonas

Reply by email

Michael Van Canneyt
to Jonas Maebe
Jonas Maebe wrote 22 lines
On 29 jun 2006, at 13:51, Carsten Bager wrote: > If I compile and run my example program and then press Crtl+C the > program terminates. I would expect that it terminate by calling > "CloseServer" procedure, but it dos not. If the program terminates > normally (time runs out) the "CloseServer" procedure is called as > expected. > > Have I misunderstood something about the ExitProc. ExitProc is only called if your program exits via the RTL. This is the case when the program exits normally, or when a run time error or unhandled exception occurs. ctrl-c is not caught by the FPC RTL. This means it is handled by the operating system, and the default action of the operating system is to simply terminate the process. The FPC RTL therefore does not get any chance to call your exitproc. I don't know whether there's a platform-independent way in the RTL to turn on the catching of ctrl-c (and converting it to an exception or run time error).

Not that I am aware of...

Michael.

Reply by email

Tomas Hajny
to Michael Van Canneyt
Michael Van Canneyt wrote 29 lines
On Thu, 29 Jun 2006, Jonas Maebe wrote: > On 29 jun 2006, at 13:51, Carsten Bager wrote: > >> If I compile and run my example program and then press Crtl+C the >> program terminates. I would expect that it terminate by calling >> "CloseServer" procedure, but it dos not. If the program terminates >> normally (time runs out) the "CloseServer" procedure is called as >> expected. >> >> Have I misunderstood something about the ExitProc. > > ExitProc is only called if your program exits via the RTL. This is the > case > when the program exits normally, or when a run time error or unhandled > exception occurs. > > ctrl-c is not caught by the FPC RTL. This means it is handled by the > operating system, and the default action of the operating system is to > simply > terminate the process. The FPC RTL therefore does not get any chance to > call > your exitproc. > > I don't know whether there's a platform-independent way in the RTL to > turn on > the catching of ctrl-c (and converting it to an exception or run time > error). Not that I am aware of...

Well, unit Crt should allow it if implemented properly (i.e. compatible to TP/BP - at least IIRC)... ;-) Not that we'd have such an implementation at the moment, though.

Tomas

Reply by email