Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
214 Beiträge
 
#4

AW: Konsolenanwendung Programmende abfragen

  Alt 20. Dez 2023, 16:50
Application ist aber in der Unit Forms deklariert. Kann ich das trotzdem verwenden, indem ich forms.pas einbinde oder gibt es eine Entsprechung bei Konsolenanwendungen?
Yes you can add Forms to console application, but it is not enough and will not solve your problem as himitsu said, you should capture the signals instead, this is cleaner and the right way with consoles.

To capture these events you need to use SetConsoleCtrlHandler
https://learn.microsoft.com/en-us/wi...olectrlhandler
https://learn.microsoft.com/en-us/wi...handlerroutine
Something like this :
Code:
function HandlerRoutine(dwCtrlType: DWORD): Bool; stdcall;
begin
  Result := false;
  if (CTRL_C_EVENT = dwCtrlType) or (CTRL_BREAK_EVENT = dwCtrlType) then
  begin

    Result := true;
  end;
end;

// setup the callback routine
SetConsoleCtrlHandler(@HandlerRoutine, True);
  Mit Zitat antworten Zitat