Chodzi oto aby niepowtarzać wiele razy tej samej instrukcji (IF). Jak umieścić procedurę ???Jak wprowadzić zabezpieczenie aby nie moża było wprowadzić wyrazów i literek???Dzieki z góry!
Oto kod:
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var liczba1,liczba2,wynik:real;
begin
if(edit1.text=)or(edit2.text=
)then
begin
showmessage('podaj liczby!!!')
end
else
begin
liczba1:=strtofloat(trim(edit1.text));
liczba2:=strtofloat(trim(edit2.text));
wynik:=liczba1+liczba2;
edit3.text:=floattostrf(wynik,ffgeneral,10,0);
end;
end;
procedure Tform1.Button2Click(Sender: TObject);
var liczba1,liczba2,wynik:real;
begin
if(edit1.text=)or(edit2.text=
)then
begin
showmessage('podaj liczby!!!')
end
else
begin
liczba1:=strtofloat(trim(edit1.text));
liczba2:=strtofloat(trim(edit2.text));
wynik:=liczba1-liczba2;
edit3.text:=floattostr(wynik);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var liczba1,liczba2,wynik:real;
begin
if(edit1.text=)or(edit2.text=
)then
begin
showmessage('podaj liczby!!!')
end
else
begin
liczba1:=strtofloat(trim(edit1.text));
liczba2:=strtofloat(trim(edit2.text));
wynik:=liczba1*liczba2;
edit3.text:=floattostr(wynik);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var liczba1,liczba2,wynik:real;
begin
if(edit1.text=)or(edit2.text=
)then
begin
showmessage('podaj liczby!!!')
end
else
begin
liczba1:=strtofloat(trim(edit1.text));
liczba2:=strtofloat(trim(edit2.text));
if liczba2<>0 then
begin
wynik:=liczba1/liczba2;
edit3.text:=floattostr(wynik);
end
else
begin
showmessage('pamiętaj cholero nie dziel przez zero');
edit2.text:='';
end;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var liczba1, wynik,liczba2,n:real;
begin
if(trim(edit1.text)=) or(trim(edit2.text)=
)then
begin
showmessage('Proszę podać liczbę');
end
else
begin
liczba2:=strtofloat(trim(edit2.text));
liczba1:=strtofloat(trim(edit1.text));
n:=liczba2*ln(liczba1);
wynik:=exp(n);
edit3.text:=floattostrf(wynik,ffgeneral,10,0);
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var liczba1,wynik:real;
begin
if(trim(edit1.text)='')then
begin
showmessage('podaj liczbę');
end
else
begin
liczba1:=strtofloat(trim(edit1.text));
wynik:=sqrt(liczba1);
edit3.text:=floattostrf(wynik,ffgeneral,10,0);
end;
end;
end.