
17.05.2009, 17:48
|
|
Участник форума
Регистрация: 10.02.2009
Сообщений: 203
С нами:
9077779
Репутация:
379
|
|
Delphi
Что не правильно, не работает программа..помогите исправить ошибки
Код:
unit fazenda_;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit; // расстояние
Edit2: TEdit; // цена литра бензина
Edit3: TEdit; // потребление бензина на 100 км
CheckBox1: TCheckBox; // True - поездка туда и обратно
Button1: TButton; // кнопка Вычислить
Label4: TLabel; // поле вывода результата расчета
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);
var
Edit: TEdit;
begin
Edit := Sender as TEdit;
// в поле Edit можно ввести только дробное число
case Key of
'0'..'9': ; // цифры
#8: ; // клавиша <Backspace>
'.',',': begin
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit.Text) <> 0
then Key := #0;
end;
#13: // клавиша <Enter>
case Edit.Tag of
1: // клавиша нажата в поле Edit1
Edit2.SetFocus; // фокус в поле Edit2
2: // клавиша нажата в поле Edit1
Edit3.SetFocus; // фокус в поле Edit3
3: // клавиша нажата в поле edit3
Button1.SetFocus; // фокус на кнопку Button1
end;
end;
end;
// щелчок на кнопке Вычислить
procedure TForm1.Button1Click(Sender: TObject);
var
rast : real; // расстояние
cena : real; // цена
potr : real; // потребление на 100 км
summ : real; // сумма
mes: string;
begin
// здесь возможно исключение типа EConvertError
// в случае, если пользователь отставит
// одно из полей ввода незаполненным
try
rast := StrToFloat(Edit1.Text);
cena := StrToFloat(Edit2.Text);
potr := StrToFloat(Edit3.Text);
except
on EConvertError do
begin
ShowMessage('Данные надо ввести во все поля!');
// попытаемся найти пустое поле
if Length(Edit1.Text) = 0
then Edit1.SetFocus
else if Length(Edit2.Text) = 0
then Edit2.SetFocus
else Edit3.SetFocus;
exit;
end;
end;
summ := (rast / 100) * potr * cena;
mes := 'Поездка на дачу';
if CheckBox1.Checked then
begin
summ := summ * 2;
mes := mes + ' и обратно';
end;
mes := mes + 'обойдется в ' + FloatToStrF(summ,ffGeneral,4,2)
+ ' руб.';
Label4.Caption := mes;
end;
end.
Последний раз редактировалось scrat; 17.05.2009 в 18:29..
|
|
|