SystemExit (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a memo and six buttons on a form. This example illustrates the different ways to exit a function.

Code

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;

Uses

Personal tools
Assistance