unit SystemExit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button6: TButton;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// BeginExample: SystemExit
// Routine: System.Exit

// BeginCode
{
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;
// EndCode
// EndExample: SystemExit
end.
