Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
5
Добавлен:
26.04.2015
Размер:
5 Кб
Скачать
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, ExtCtrls, Mask;

type
  TForm1 = class(TForm)
    Button1: TButton;
    GroupBox1: TGroupBox;
    ComboBox1: TComboBox;
    StatusBar1: TStatusBar;
    Panel2: TPanel;
    RadioButton5: TRadioButton;
    GroupBox3: TGroupBox;
    Edit2: TEdit;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    GroupBox4: TGroupBox;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    RadioButton4: TRadioButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure RadioButton5Click(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit4KeyPress(Sender: TObject; var Key: Char);
    procedure Edit5Change(Sender: TObject);
    procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
    procedure RadioButton4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Num1,Num2,Num3:Integer;
  Num4:Real;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Close
end;

procedure TForm1.FormActivate(Sender: TObject);
var i:Integer;
begin
 // установка фокуса на Edit2
  Edit2.SetFocus;
 // Очистка списка
  ComboBox1.Items.Clear;
 // формирование списка ComboBox1
  for i:=0 to 10 do
   ComboBox1.Items.Append('Строка'+IntToStr(i));
 // установка в поле редактирования значения из списка
  ComboBox1.Text:=ComboBox1.Items[10];
 // установка ширины полей StatusBar
  for i:=0 to 6 do
    StatusBar1.Panels[i].Width:=60;
  Edit3.Text:=''; Edit4.Text:=''; Edit5.Text:='';
end;

procedure TForm1.RadioButton1Click(Sender: TObject);
// редактирование
begin
  Edit2.PassWordChar:=#0; Edit2.MaxLength:=0;// снятие пароля и длины
  Edit2.ReadOnly:=False;
  Edit2.SetFocus;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
// просмотр
begin
 Edit2.ReadOnly:=True;// установка на просмотр
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
// пароль длиной 5
begin
   Edit2.Text:='';// очистка поля редактирования
   Edit2.ReadOnly:=False;// снятие  установки на просмотр
   Edit2.PassWordChar:='+';Edit2.MaxLength:=5;
end;

procedure TForm1.RadioButton5Click(Sender: TObject);
// список - выбор
begin
 ComboBox1.Style:=csDropDownList;
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
 StatusBar1.Panels[0].Text:=Edit2.Text;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  StatusBar1.Panels[1].Text:=ComboBox1.Text;
end;

procedure TForm1.Edit3Change(Sender: TObject);
 // ввод целого  1 способ
var Code:Integer;
begin
 if Edit3.Text<>'' then
  begin
   Val(Edit3.Text,Num1,Code);
   if Code =0 then  StatusBar1.Panels[2].Text:=IntToStr(Num1)
     else // не число
       begin
        ShowMessage('Это не число');
        StatusBar1.Panels[2].Text:='';Edit3.Text:=''
       end;
  end
                  else StatusBar1.Panels[2].Text:='';

end;

procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
 // ввод целого 2 способ
begin
  if not (Key in['0'..'9',#13,#8])  then Key:=#0;
  if Key = #13 then
   begin
    Num2:=StrToInt(Edit4.Text);
    StatusBar1.Panels[3].Text:=IntToStr(Num2);
   end;
end;

procedure TForm1.Edit5Change(Sender: TObject);
 // ввод вещественного 1 способ
var Code:Integer;
begin
 if Edit5.Text<>'' then
  begin
   Val(Edit5.Text,Num4,Code);
    if Code =0 then  StatusBar1.Panels[6].Text:=FloatToStr(Num4)
               else // не число
      begin
       ShowMessage('Это не число');
       StatusBar1.Panels[6].Text:='';Edit3.Text:=''
      end;
  end;
end;

procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
 //дополнение списка значением из поля редактирования по нажатию Enter
begin
  if RadioButton4.Checked then
   if Key =#13  then ComboBox1.Items.Append(ComboBox1.Text);
  StatusBar1.Panels[1].Text:=ComboBox1.Text;
end;

procedure TForm1.RadioButton4Click(Sender: TObject);
begin // список дополнение
  ComboBox1.Style:=csDropDown;
end;

procedure TForm1.Button2Click(Sender: TObject);
// Сумма
begin
  Num3:=Num1+Num2;
  StatusBar1.Panels[4].Text:=IntToStr(Num3);
end;

procedure TForm1.Button4Click(Sender: TObject);
// Очистить
var i:Integer;
begin
 for i:=0 to StatusBar1.Panels.Count-1 do
    StatusBar1.Panels[i].Text:='';
  Edit3.Text:=''; Edit4.Text:=''; Edit5.Text:='';
end;

procedure TForm1.Button3Click(Sender: TObject);
// Деление
begin
 if Num2 <> 0 then
  begin
   Num4:=Num1/Num2;StatusBar1.Panels[5].Text:=FormatFloat('#0.##',Num4);
  end
               else ShowMessage('Деление на ноль');

end;



end.
Соседние файлы в папке Ввод-Вывод_Пример