Загрузка данных


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Edit3: TEdit;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    ComboBox1: TComboBox;
    Memo1: TMemo;

    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);

    procedure EditDigitsKeyPress(Sender: TObject; var Key: Char);
    procedure EditLettersKeyPress(Sender: TObject; var Key: Char);

  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  Pass: string;
begin
  Pass := InputBox('Вход', 'Введите пароль:', '');

  if Pass <> '123' then
  begin
    ShowMessage('Неверный пароль!');
    Application.Terminate;
  end;

  { Разрешаем ввод текста в ComboBox }
  ComboBox1.Style := csDropDown;
end;

{ Только цифры }
procedure TForm1.EditDigitsKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9', #8]) then
    Key := #0;
end;

{ Только буквы }
procedure TForm1.EditLettersKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in
    ['A'..'Z', 'a'..'z',
     'А'..'Я', 'а'..'я',
     'Ё', 'ё', #8, ' ']) then
    Key := #0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  F: TextFile;
  Sport: string;
begin
  Sport := Trim(ComboBox1.Text);

  if Sport = '' then
  begin
    ShowMessage('Введите вид спорта!');
    Exit;
  end;

  AssignFile(F, 'Sport.txt');

  if FileExists('Sport.txt') then
    Append(F)
  else
    Rewrite(F);

  { Сохраняем только вид спорта }
  WriteLn(F, Sport);

  CloseFile(F);

  Memo1.Lines.Add(Sport);

  { Если такого спорта нет — добавляем в список }
  if ComboBox1.Items.IndexOf(Sport) = -1 then
    ComboBox1.Items.Add(Sport);

  Edit1.Clear;
  Edit3.Clear;
  Edit4.Clear;
  Edit5.Clear;
  ComboBox1.Text := '';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Form2.Show;
end;

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

end.