Вариант 1
procedure TForm1.Button1Click(Sender: TObject);
var a, b,s,p,d,r: real; // объявление локальных переменных
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
s:= a + b;
label4.Caption:= floattostr(s);
end;
procedure TForm1.Button2Click(Sender: TObject);
var a, b,s,p,d,r: real; // объявление локальных переменных
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
r:= a - b;
label4.Caption:= floattostr(r);
end;
procedure TForm1.Button3Click(Sender: TObject);
var a, b,s,p,d,r: real; // объявление локальных переменных
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
p:= a * b;
label4.Caption:= floattostr(p);
end;
procedure TForm1.Button4Click(Sender: TObject);
var a, b,s,p,d,r: real; // объявление локальных переменных
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
if b <> 0 then
begin
d:= a / b;
label4.Caption:= floattostrF(d,ffFixed,5,2);
label5.Caption:= floattostr(d); //для наглядности выполним вывод без использования формата
end
else label4.Caption:='деление на ноль недопустимо' ;
end;
|
var
Form1: TForm1;
var a, b,s,p,d,r: real; //переводим локальные переменные в статус глобальных переменных
implementation
{$R *.lfm}
{ TForm1 }
Вариант 2
procedure TForm1.Button1Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
s:= a + b;
label4.Caption:= floattostr(s);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
r:= a - b;
label4.Caption:= floattostr(r);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
p:= a * b;
label4.Caption:= floattostr(p);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
if b <> 0 then
begin
d:= a / b;
label4.Caption:= floattostrF(d,ffFixed,5,2);
label5.Caption:= floattostr(d);
end
else label4.Caption:='деление на ноль недопустимо' ;
end;
|