Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Add;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TAddForm = class(TForm)
- Label1: TLabel;
- Edit1: TEdit;
- Label2: TLabel;
- Edit2: TEdit;
- Label3: TLabel;
- Edit3: TEdit;
- Label4: TLabel;
- Edit4: TEdit;
- Label5: TLabel;
- Button1: TButton;
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure Edit1Change(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Edit2KeyPress(Sender: TObject; var Key: Char);
- procedure Edit3KeyPress(Sender: TObject; var Key: Char);
- procedure Edit4KeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- AddForm: TAddForm;
- implementation
- Uses
- Base, ChangeMenu, Menu, DeleteRef, Change;
- {$R *.dfm}
- procedure TAddForm.Button1Click(Sender: TObject);
- var
- s: String;
- i, kol: Integer;
- begin
- kol := 0;
- s := Edit4.Text;
- for i := 1 to length(s) do
- if s[i] = '.' then
- inc(kol);
- if kol <> 2 then
- MessageDlg('Введите дату в формате день.месяц.год', mtError, [mbOK], 0)
- else
- begin
- Inc(n);
- SetLength(Ref, n);
- Ref[n - 1].Topic := Edit1.Text;
- Ref[n - 1].Author := Edit2.Text;
- Ref[n - 1].Str := StrToInt(Edit3.Text);
- Ref[n - 1].Date := Edit4.Text;
- Edit1.Text := '';
- Edit2.Text := '';
- Edit3.Text := '';
- Edit4.Text := '';
- Seek(MyFile, FileSize(MyFile));
- Write(MyFile, Ref[n - 1]);
- BaseForm.Show;
- AddForm.Hide;
- end;
- end;
- procedure TAddForm.Edit1Change(Sender: TObject);
- var
- IsValid1, IsValid2, IsValid3, IsValid4: Boolean;
- begin
- if Edit1.Text <> '' then
- IsValid1 := True
- else
- IsValid1 := False;
- if Edit2.Text <> '' then
- IsValid2 := True
- else
- IsValid2 := False;
- if Edit3.Text <> '' then
- IsValid3 := True
- else
- IsValid3 := False;
- if Edit4.Text <> '' then
- IsValid4 := True
- else
- IsValid4 := False;
- if (IsValid1) and (IsValid2) and (IsValid3) and (IsValid4) then
- Button1.Enabled := True
- else
- Button1.Enabled := False;
- end;
- procedure TAddForm.Edit2KeyPress(Sender: TObject; var Key: Char);
- const
- NotDigit: set of Char = ['0'..'9', '.', ','];
- begin
- with (Sender as TEdit) do
- begin
- if Key in NotDigit then
- Key := #0;
- end;
- end;
- procedure TAddForm.Edit3KeyPress(Sender: TObject; var Key: Char);
- const
- Digit: set of Char = ['0'..'9', #8];
- begin
- with (Sender as TEdit) do
- begin
- if not(Key in Digit) then
- Key := #0;
- end;
- end;
- procedure TAddForm.Edit4KeyPress(Sender: TObject; var Key: Char);
- const
- Digit: set of Char = ['0'..'9', #8, '.'];
- begin
- with (Sender as TEdit) do
- begin
- if not(Key in Digit) then
- Key := #0;
- end;
- end;
- procedure TAddForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- BaseForm.Show;
- MenuForm.Hide;
- ChangeMenuForm.Hide;
- AddForm.Hide;
- DeleteForm.Hide;
- ChangeForm.Hide;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement