Advertisement
MadCortez

Untitled

Mar 23rd, 2021
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.25 KB | None | 0 0
  1. unit Add;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  8.  
  9. type
  10.   TAddForm = class(TForm)
  11.     Label1: TLabel;
  12.     Edit1: TEdit;
  13.     Label2: TLabel;
  14.     Edit2: TEdit;
  15.     Label3: TLabel;
  16.     Edit3: TEdit;
  17.     Label4: TLabel;
  18.     Edit4: TEdit;
  19.     Label5: TLabel;
  20.     Button1: TButton;
  21.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  22.     procedure Edit1Change(Sender: TObject);
  23.     procedure Button1Click(Sender: TObject);
  24.     procedure Edit2KeyPress(Sender: TObject; var Key: Char);
  25.     procedure Edit3KeyPress(Sender: TObject; var Key: Char);
  26.     procedure Edit4KeyPress(Sender: TObject; var Key: Char);
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32.  
  33. var
  34.   AddForm: TAddForm;
  35.  
  36. implementation
  37.  
  38. Uses
  39.    Base, ChangeMenu, Menu, DeleteRef, Change;
  40.  
  41. {$R *.dfm}
  42.  
  43. procedure TAddForm.Button1Click(Sender: TObject);
  44. var
  45.    s: String;
  46.    i, kol: Integer;
  47. begin
  48.    kol := 0;
  49.    s := Edit4.Text;
  50.    for i := 1 to length(s) do
  51.       if s[i] = '.' then
  52.          inc(kol);
  53.    if kol <> 2 then
  54.       MessageDlg('Введите дату в формате день.месяц.год', mtError, [mbOK], 0)
  55.    else
  56.    begin
  57.       Inc(n);
  58.       SetLength(Ref, n);
  59.       Ref[n - 1].Topic := Edit1.Text;
  60.       Ref[n - 1].Author := Edit2.Text;
  61.       Ref[n - 1].Str := StrToInt(Edit3.Text);
  62.       Ref[n - 1].Date := Edit4.Text;
  63.       Edit1.Text := '';
  64.       Edit2.Text := '';
  65.       Edit3.Text := '';
  66.       Edit4.Text := '';
  67.       Seek(MyFile, FileSize(MyFile));
  68.       Write(MyFile, Ref[n - 1]);
  69.       BaseForm.Show;
  70.       AddForm.Hide;
  71.    end;
  72. end;
  73.  
  74. procedure TAddForm.Edit1Change(Sender: TObject);
  75. var
  76.    IsValid1, IsValid2, IsValid3, IsValid4: Boolean;
  77. begin
  78.    if Edit1.Text <> '' then
  79.       IsValid1 := True
  80.    else
  81.       IsValid1 := False;
  82.    if Edit2.Text <> '' then
  83.       IsValid2 := True
  84.    else
  85.       IsValid2 := False;
  86.    if Edit3.Text <> '' then
  87.       IsValid3 := True
  88.    else
  89.       IsValid3 := False;
  90.    if Edit4.Text <> '' then
  91.       IsValid4 := True
  92.    else
  93.       IsValid4 := False;
  94.    if (IsValid1) and (IsValid2) and (IsValid3) and (IsValid4) then
  95.       Button1.Enabled := True
  96.    else
  97.       Button1.Enabled := False;
  98. end;
  99.  
  100. procedure TAddForm.Edit2KeyPress(Sender: TObject; var Key: Char);
  101. const
  102.    NotDigit: set of Char = ['0'..'9', '.', ','];
  103. begin
  104.    with (Sender as TEdit) do
  105.    begin
  106.       if Key in NotDigit then
  107.          Key := #0;
  108.    end;
  109. end;
  110.  
  111. procedure TAddForm.Edit3KeyPress(Sender: TObject; var Key: Char);
  112. const
  113.    Digit: set of Char = ['0'..'9', #8];
  114. begin
  115.    with (Sender as TEdit) do
  116.    begin
  117.       if not(Key in Digit) then
  118.          Key := #0;
  119.    end;
  120. end;
  121.  
  122. procedure TAddForm.Edit4KeyPress(Sender: TObject; var Key: Char);
  123. const
  124.    Digit: set of Char = ['0'..'9', #8, '.'];
  125. begin
  126.    with (Sender as TEdit) do
  127.    begin
  128.       if not(Key in Digit) then
  129.          Key := #0;
  130.    end;
  131. end;
  132.  
  133. procedure TAddForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  134. begin
  135.    BaseForm.Show;
  136.    MenuForm.Hide;
  137.    ChangeMenuForm.Hide;
  138.    AddForm.Hide;
  139.    DeleteForm.Hide;
  140.    ChangeForm.Hide;
  141. end;
  142.  
  143. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement