unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask;
type
TForm1 =
class
(TForm)
edt1: TEdit;
edt2: TEdit;
rb1: TRadioButton;
rb2: TRadioButton;
btn1: TButton;
lbl1: TLabel;
procedure
edt1KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
edt2KeyPress(Sender: TObject;
var
Key:
Char
);
procedure
btn1Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
R1,R2,R:
Real
;
implementation
{$R *.dfm}
procedure
TForm1
.
edt1KeyPress(Sender: TObject;
var
Key:
Char
);
begin
case
Key
of
'0'
..
'9'
, #
8
: ;
','
,
'.'
:
begin
key:=DecimalSeparator;
if
Pos(DecimalSeparator, edt1
.
Text)<>
0
then
Key:=chr(
0
);
end
;
#
13
: Edt2
.
SetFocus;
else
Key:=chr(
0
);
end
;
end
;
procedure
TForm1
.
edt2KeyPress(Sender: TObject;
var
Key:
Char
);
begin
case
Key
of
'0'
..
'9'
, #
8
: ;
','
,
'.'
:
begin
key:=DecimalSeparator;
if
Pos(DecimalSeparator, edt2
.
Text)<>
0
then
Key:=chr(
0
);
end
;
#
13
: btn1
.
SetFocus;
else
Key:=chr(
0
);
end
;
end
;
procedure
TForm1
.
btn1Click(Sender: TObject);
begin
if
(Edt1
.
Text =
''
)
then
begin
Edt1
.
SetFocus;
ShowMessage(
' '
);
Exit;
end
;
R1:=StrToFloat(edt1
.
text);
if
(Edt2
.
Text =
''
)
then
begin
Edt2
.
SetFocus;
ShowMessage(
' '
);
Exit;
end
;
R2:=StrToFloat(edt2
.
Text);
<b>
if
rb1
.
Checked
then
</b>
if
R1+R2=
0
then
begin
ShowMessage(
' '
);
Exit;
end
;
begin
R:=R1+R2 ;
end
;
<b>
if
rb2
.
Checked
then
</b>
if
R1+R2=
0
then
begin
ShowMessage(
'Îäíî èç çíà÷åíèé ðàâíî 0'
);
Exit;
end
;
begin
R:=(R1*R2)/(R1+R2);
end
;
lbl1
.
Caption:=FloatToStr(R);
end
;
end
.