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
BreakForces a jump out of a single loop
ContinueForces a jump to the next iteration of a loop
GotoForces a jump to a label, regardless of nesting
HaltTerminates the program with an optional dialog
RunErrorTerminates the program with an error dialog
 Download this web site as a Windows program.




 
Example code : Exit a proc when a user cancels data entry
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;
Show 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 . All rights reserved.  |  Home Page