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)
- LAbout: TLabel;
- Topic: TEdit;
- LTopic: TLabel;
- SecName: TEdit;
- LSecName: TLabel;
- Str: TEdit;
- LStr: TLabel;
- Date: TEdit;
- LDate: TLabel;
- AddButton: TButton;
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure TopicChange(Sender: TObject);
- procedure AddButtonClick(Sender: TObject);
- procedure SecNameKeyPress(Sender: TObject; var Key: Char);
- procedure StrKeyPress(Sender: TObject; var Key: Char);
- procedure DateKeyPress(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.AddButtonClick(Sender: TObject);
- var
- s: String;
- i, kol: Integer;
- begin
- kol := 0;
- s := Date.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 := Topic.Text;
- Ref[n - 1].Author := SecName.Text;
- Ref[n - 1].Str := StrToInt(Str.Text);
- Ref[n - 1].Date := Date.Text;
- Topic.Text := '';
- SecName.Text := '';
- Str.Text := '';
- Date.Text := '';
- Seek(MyFile, FileSize(MyFile));
- Write(MyFile, Ref[n - 1]);
- BaseForm.Show;
- AddForm.Hide;
- end;
- end;
- procedure TAddForm.TopicChange(Sender: TObject);
- var
- IsValid1, IsValid2, IsValid3, IsValid4: Boolean;
- begin
- if Topic.Text <> '' then
- IsValid1 := True
- else
- IsValid1 := False;
- if SecName.Text <> '' then
- IsValid2 := True
- else
- IsValid2 := False;
- if Str.Text <> '' then
- IsValid3 := True
- else
- IsValid3 := False;
- if Date.Text <> '' then
- IsValid4 := True
- else
- IsValid4 := False;
- if (IsValid1) and (IsValid2) and (IsValid3) and (IsValid4) then
- AddButton.Enabled := True
- else
- AddButton.Enabled := False;
- end;
- procedure TAddForm.SecNameKeyPress(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.StrKeyPress(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.DateKeyPress(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