Board index » delphi » To stop program which is running in TP 7.0

To stop program which is running in TP 7.0

How to stop (definitely, not just by pause/break key) program
which is running and turn back to the edition in TP 7.0?
 

Re:To stop program which is running in TP 7.0


"Mike G." <g...@wp.pl> schreef in bericht
news:ad2ai3$7k3$1@news.tpi.pl...

Quote
> How to stop (definitely, not just by pause/break key) program
> which is running and turn back to the edition in TP 7.0?

I assume that you want to interrupt the program manually for the reason
that is is stuck in an endless loop?

CNTRL C    or CNTRL BREAK usually works.

There is no guarantee that the program will always interrupt however.

Femme

Re:To stop program which is running in TP 7.0


Mike G. wrote in <ad2ai3$7k...@news.tpi.pl>

Quote
> How to stop (definitely, not just by pause/break key) program
> which is running and turn back to the edition in TP 7.0?

  Like this?

(*
    Escape From a Program
    Version: 23/05/2002
    (c) Great Hedgehog's SRL 2002
    Web:  http://ghsrl.newmail.ru
    E-Mail:  ghsrl^mail.ru
*)

uses Dos;

Const
  ExitKey = $2D00; {! $2D00 - this is Alt+X !}

var
  KbdIntVec : Procedure;
  SaveExitProc : Pointer;

  ReadKB: Boolean;
    {True = set this
              while your program does any calculations
              or other thigs which doesn't required KeyBoard
     False = set this
               while your program waits user's input
                 via CRT.ReadKey, System.Read/ReadLn, etc
             to pass other keys (except ExitKey) to such procedures
    }

{$F+}
procedure RestoreExitProc;
begin
  (****  DONE part - do not cange it!  ***)
  SetIntVec($9,@KbdIntVec);
  ExitProc := SaveExitProc;
  (****  End of DONE part - do not cange it!  ***)

  { and more...
     Close files
     Free XMS/EMS memory
     Message for user
     etc
  ...for properly exit to OS}
end;

procedure Keyclick; interrupt;
Label
  _Exit;
begin
  inline ($9C); { PUSHF -- Push flags }
  { Call old ISR using saved vector }
  KbdIntVec;
  asm
    mov  ah, 1
    int  16h
    push AX
    mov  al, 0
    pop  AX
    je   _Exit
    cmp  ReadKB, True
    jne  @Continue
    mov  ah, 0
    int  16h
  @Continue:
    cmp  AX, ExitKey
    jne  _Exit
  end;
  Halt; {or Halt(<ExitCode>) to inform parent process}
_Exit:
end;
{$F-}

begin
  (****  Initial part - do not cange it!  ***)
  SaveExitProc := ExitProc;
  ExitProc := @RestoreExitProc;

  { Insert ISR into keyboard chain }
  GetIntVec($9,@KbdIntVec);
  SetIntVec($9,Addr(Keyclick));
  (****  End of Initial part - do not cange it!  ***)

  {ReadKB:= True;}
  {Uncomment previous line to see how does
     it work w/o ReadLn;}

  WriteLn;
  WriteLn(' Press Alt+X to Break me :))');
  Repeat
    if not ReadKB then begin
      ReadLn;
      Break;
    end;
  Until False;
end.

--
   Varjonov Konstantin       varkos^mail.ru      http://ghsrl.newmail.ru

Other Threads