Exits from the current procedure.
procedure Exit;
Exit();
In Delphi, the Exit procedure immediately passes control away from the current procedure. If the current procedure is the main program, Exit causes the program to terminate.
Exit will cause the calling procedure to continue with the statement after the point at which the procedure was called.
function DoSomething(aInteger: integer): string begin if aInteger < 0 then begin Exit(‘Negative’); end; Result := ‘Positive’; end;
Delphi Examples:
{ This example uses a memo and six buttons on a form. This example illustrates the different ways to exit a function. } function GetAString(input: string): string; var mystring : string; begin mystring := DateToStr(Date); if (input = 'date') then Exit(mystring); if (input = 'Tuesday') then begin Result := 'Tuesday'; Exit; end; Result := 'nothing'; end; function GetANumber(input: string): Integer; var myInt : Integer; begin myInt := Round(Date); if (input = 'date') then Exit(myInt); if (input = 'Tuesday') then begin Result := 2; Exit; end; Result := 0; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Add(GetAString('date')); end; procedure TForm1.Button2Click(Sender: TObject); begin Memo1.Lines.Add(GetAString('babble')); end; procedure TForm1.Button3Click(Sender: TObject); begin Memo1.Lines.Add(GetAString('Tuesday')); end; procedure TForm1.Button4Click(Sender: TObject); begin Memo1.Lines.Add(IntToStr(GetANumber('date'))); end; procedure TForm1.Button5Click(Sender: TObject); begin Memo1.Lines.Add(IntToStr(GetANumber('nothing'))); end; procedure TForm1.Button6Click(Sender: TObject); begin Memo1.Lines.Add(IntToStr(GetANumber('Tuesday'))); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|