Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit EditUnit;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, MainUnit, Vcl.Samples.Spin, Vcl.StdCtrls,
- Vcl.Menus, AddUnit;
- type
- TEditForm = class(TForm)
- TelephoneLabel: TLabel;
- SurnameLabel: TLabel;
- YearLabel: TLabel;
- EditButton: TButton;
- TelephoneEdit: TEdit;
- SurnameEdit: TEdit;
- YearSpinEdit: TSpinEdit;
- GoBackButton: TButton;
- ResultLabel: TLabel;
- MainMenu: TMainMenu;
- InstructionMenu: TMenuItem;
- procedure TelephoneEditKeyPress(Sender: TObject; var Key: Char);
- procedure SurnameEditKeyPress(Sender: TObject; var Key: Char);
- procedure FormShow(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure GoBackButtonClick(Sender: TObject);
- procedure EditButtonClick(Sender: TObject);
- procedure TelephoneEditChange(Sender: TObject);
- procedure SurnameEditChange(Sender: TObject);
- procedure YearSpinEditChange(Sender: TObject);
- procedure InstructionMenuClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- EditForm: TEditForm;
- implementation
- {$R *.dfm}
- procedure TEditForm.EditButtonClick(Sender: TObject);
- var
- CurrSub: TSubscriber;
- begin
- ResultLabel.Visible := false;
- if AddForm.IsTelCorrect(TelephoneEdit) and AddForm.IsSurnameCorrect(SurnameEdit) then
- begin
- CurrSub.telephoneNumber := StrToInt(TelephoneEdit.Text);
- CurrSub.yearOfReg := YearSpinEdit.value;
- CurrSub.surname := SurnameEdit.text;
- Subscribers[SelectedSub] := CurrSub;
- ResultLabel.Visible := true;
- WriteSubsInFile();
- end
- else
- Application.MessageBox('Введены некорректные данные!', 'Ошибка!', MB_ICONERROR);
- end;
- procedure TEditForm.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- ResultLabel.Visible := false;
- EditForm.hide;
- MainForm.Show;
- end;
- procedure TEditForm.FormCreate(Sender: TObject);
- begin
- SurnameEdit.MaxLength := MAX_SURNAME_LENGTH;
- TelephoneEdit.MaxLength := MAX_TELEPHONE_LENGTH;
- YearSpinEdit.MinValue := MIN_YEAR_OF_REGISTRATION;
- YearSpinEdit.MaxValue := MAX_YEAR_OF_REGISTRATION;
- YearSpinEdit.MaxLength := MIN_YEAR_OF_REGISTRATION_LENGTH;
- end;
- procedure TEditForm.FormShow(Sender: TObject);
- begin
- SurnameEdit.Text := Subscribers[SelectedSub].surname;
- TelephoneEdit.Text := IntToStr(Subscribers[SelectedSub].telephoneNumber);
- YearSpinEdit.Value := Subscribers[SelectedSub].yearOfReg;
- end;
- procedure TEditForm.GoBackButtonClick(Sender: TObject);
- begin
- ResultLabel.Visible := false;
- EditForm.hide;
- MainForm.Show;
- end;
- procedure TEditForm.InstructionMenuClick(Sender: TObject);
- begin
- MessageDlg('Окно редактирования.' + #13#10 + #13#10 +
- 'Для успешного изменения абонента необходимо заполнить все поля для ввода.'
- + #13#10 + #13#10 + 'Для возвращения к главному окну нажмите "Назад".',
- MtInformation, [mbOk], 0);
- end;
- procedure TEditForm.SurnameEditChange(Sender: TObject);
- begin
- ResultLabel.Visible := false;
- end;
- procedure TEditForm.SurnameEditKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key <> #08) then
- begin
- if not(Key in LETTERS) then
- Key := #0;
- end;
- end;
- procedure TEditForm.TelephoneEditChange(Sender: TObject);
- begin
- ResultLabel.Visible := false;
- end;
- procedure TEditForm.TelephoneEditKeyPress(Sender: TObject; var Key: Char);
- begin
- if (Key <> #08) then
- begin
- if not(Key in DIGITS) then
- Key := #0;
- end;
- end;
- procedure TEditForm.YearSpinEditChange(Sender: TObject);
- begin
- ResultLabel.Visible := false;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement