unit Zins1B;

interface

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

type
  TZins = class (TObject)
    Kapital,
    Prozent,
    Zinsen: Single;
    constructor Create;
    function SetKapital (Txt: String): Boolean;
    function SetProzent (Txt: String): Boolean;
    function SetZinsen  (Txt: String): Boolean;
    function GetKapital: String;
    function GetProzent: String;
    function GetZinsen:  String;
  end;

  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure SetZero;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Zins : TZins;
  Modus: Integer;

implementation

{$R *.DFM}

constructor TZins.Create;
begin
  inherited Create;
end;

function TZins.SetKapital (Txt: String): Boolean;
begin
  try
    Kapital := StrToFloat (Txt);
    if (Kapital = 0) then SetKapital := false else SetKapital := true;
  except
    SetKapital := false;
  end;
end;

function TZins.SetProzent (Txt: String): Boolean;
begin
  try
    Prozent := StrToFloat (Txt);
    if (Prozent = 0) then SetProzent := false else SetProzent := true;
  except
    SetProzent := false;
  end;
end;

function TZins.SetZinsen (Txt: String): Boolean;
begin
  try
    Zinsen := StrToFloat (Txt);
    if (Zinsen = 0) then SetZinsen := false else SetZinsen := true;
  except
    SetZinsen := false;
  end;
end;

function TZins.GetKapital: String;
begin
  Kapital := Zinsen * 100 / Prozent;
  GetKapital := FloatToStrF(Kapital,ffNumber,8,2);
end;

function TZins.GetProzent: String;
begin
  Prozent := Zinsen * 100 / Kapital;
  GetProzent := FloatToStrF(Prozent,ffNumber,8,2);
end;

function TZins.GetZinsen:  String;
begin
  Zinsen := Kapital * Prozent / 100;
  GetZinsen := FloatToStrF(Zinsen,ffNumber,8,2);
end;

procedure TForm1.SetZero;
begin
  Zins.Kapital := 0;
  Zins.Prozent := 0;
  Zins.Zinsen  := 0;
  Edit1.Text := '0';
  Edit2.Text := '0';
  Edit3.Text := '0';
  Modus := 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Zins := TZins.Create;
  SetZero;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetZero;
  Label1.Caption :=
    'Setze nur die gesuchte Größe auf null!';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Label1.Caption := 'Das ist das Ergebnis';
  if not Zins.SetKapital (Edit1.Text) then inc (Modus);
  if not Zins.SetProzent (Edit2.Text) then inc (Modus,10);
  if not Zins.SetZinsen  (Edit3.Text) then inc (Modus,100);
  case Modus of
    1  : Edit1.Text := Zins.GetKapital;
    10 : Edit2.Text := Zins.GetProzent;
    100: Edit3.Text := Zins.GetZinsen;
    else
      Label1.Caption := 'Keine oder zu viele Nullen!';
  end;
  Modus := 0;
end;

end.
