ExitProc

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ExitProc

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;
  ExitProc:=@CloseServer;
  sleep(10000);
  WriteLn('--Close--');
end.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ExitProc

Jonas Maebe-2

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


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ExitProc

Michael Van Canneyt


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...

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: ExitProc

Tomas Hajny
Michael Van Canneyt wrote:

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal