DelphiBasics
Exit
Procedure
Exit abruptly from a function or procedure System unit
 procedure Exit ;
Description
The Exit procedure abruptly terminates the current function or procedure.
 
If exiting a function, then Result contains the last set value.
 
Warning : use with caution - jumping is a concept at odds with structured coding - it makes code maintenance difficult.
Related commands
Break Forces a jump out of a single loop
Continue Forces a jump to the next iteration of a loop
Goto Forces a jump to a label, regardless of nesting
Halt Terminates the program with an optional dialog
RunError Terminates the program with an error dialog
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
Example code : Exit a proc when a user cancels data entry
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    function AskForName: string;
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

begin
  // Ask the user for their name
  ShowMessage('Name = '+AskForName);
end;

// Ask the user for first and second names
function TForm1.AskForName: string;
var
  firstName, secondName : string;
begin
  Result := 'Lazy person';
  repeat
    if not InputQuery('Test program', 'First name :', firstName)
    then Exit;
    if not InputQuery('Test program', 'Second name :', secondName)
    then Exit;
  until (firstName <> '') or (secondName <> '');

  Result := firstName + ' ' + secondName;
end;
 
end.
Hide full unit code
   If the user cancels from the first or second name dialogs, the ShowMessage dialog gives:
  
   Name = Lazy person
 
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Contact the author  |  Home Page