Advertisement
MadCortez

Untitled

Mar 23rd, 2021
338
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.     LAbout: TLabel;
  12.     Topic: TEdit;
  13.     LTopic: TLabel;
  14.     SecName: TEdit;
  15.     LSecName: TLabel;
  16.     Str: TEdit;
  17.     LStr: TLabel;
  18.     Date: TEdit;
  19.     LDate: TLabel;
  20.     AddButton: TButton;
  21.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  22.     procedure TopicChange(Sender: TObject);
  23.     procedure AddButtonClick(Sender: TObject);
  24.     procedure SecNameKeyPress(Sender: TObject; var Key: Char);
  25.     procedure StrKeyPress(Sender: TObject; var Key: Char);
  26.     procedure DateKeyPress(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.AddButtonClick(Sender: TObject);
  44. var
  45.    s: String;
  46.    i, kol: Integer;
  47. begin
  48.    kol := 0;
  49.    s := Date.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 := Topic.Text;
  60.       Ref[n - 1].Author := SecName.Text;
  61.       Ref[n - 1].Str := StrToInt(Str.Text);
  62.       Ref[n - 1].Date := Date.Text;
  63.       Topic.Text := '';
  64.       SecName.Text := '';
  65.       Str.Text := '';
  66.       Date.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.TopicChange(Sender: TObject);
  75. var
  76.    IsValid1, IsValid2, IsValid3, IsValid4: Boolean;
  77. begin
  78.    if Topic.Text <> '' then
  79.       IsValid1 := True
  80.    else
  81.       IsValid1 := False;
  82.    if SecName.Text <> '' then
  83.       IsValid2 := True
  84.    else
  85.       IsValid2 := False;
  86.    if Str.Text <> '' then
  87.       IsValid3 := True
  88.    else
  89.       IsValid3 := False;
  90.    if Date.Text <> '' then
  91.       IsValid4 := True
  92.    else
  93.       IsValid4 := False;
  94.    if (IsValid1) and (IsValid2) and (IsValid3) and (IsValid4) then
  95.       AddButton.Enabled := True
  96.    else
  97.       AddButton.Enabled := False;
  98. end;
  99.  
  100. procedure TAddForm.SecNameKeyPress(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.StrKeyPress(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.DateKeyPress(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