
10.08.2011, 16:03
|
Прохожий
|
|
Регистрация: 28.07.2011
Сообщения: 34
Репутация: 12
|
|
RadioButton. Не могу справится
Пишу вот для обучения маленькую программку для расчета сопротивления электрической цепи для параллельного и последовательного соединения сопротивлений. Для выбора способа соединения (последовательного или параллельного) использую RadioButton. Так вот почему то при нажатии button1 расчитыватся только RadioButton2.checked, и совсем не расчитывается RadioButton2.checked. Где ошибке не могу понять.
Код:
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
{ Private declarations }
public
{ Public declarations }
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);
if rb1.Checked then
if R1+R2=0 then
begin
ShowMessage(' ');
Exit;
end;
begin
R:=R1+R2 ;
end;
if rb2.Checked then
if R1+R2=0 then
begin
ShowMessage('Îäíî èç çíà÷åíèé ðàâíî 0');
Exit;
end;
begin
R:=(R1*R2)/(R1+R2);
end;
lbl1.Caption:=FloatToStr(R);
end;
end.
|