Advertisement
MadCortez

Untitled

Mar 23rd, 2021
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.19 KB | None | 0 0
  1. unit Change;
  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, System.Actions, Vcl.ActnList,
  8.   Vcl.StdCtrls;
  9.  
  10. type
  11.   TChangeForm = class(TForm)
  12.     Refs: TComboBox;
  13.     LTopic: TLabel;
  14.     LSecName: TLabel;
  15.     LStr: TLabel;
  16.     LDate: TLabel;
  17.     Topic: TEdit;
  18.     SecName: TEdit;
  19.     Str: TEdit;
  20.     Date: TEdit;
  21.     Save: TButton;
  22.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  23.     procedure RefsDropDown(Sender: TObject);
  24.     procedure RefsClick(Sender: TObject);
  25.     procedure FormShow(Sender: TObject);
  26.     procedure SaveClick(Sender: TObject);
  27.     procedure SecNameKeyPress(Sender: TObject; var Key: Char);
  28.     procedure StrKeyPress(Sender: TObject; var Key: Char);
  29.     procedure DateKeyPress(Sender: TObject; var Key: Char);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.   end;
  35.  
  36. var
  37.   ChangeForm: TChangeForm;
  38.   ChangeIndex: Integer;
  39.   Flag: Boolean;
  40.  
  41. implementation
  42.  
  43. Uses
  44.    Base, ChangeMenu, Add, DeleteRef, Menu;
  45.  
  46. {$R *.dfm}
  47.  
  48. procedure TChangeForm.SaveClick(Sender: TObject);
  49. var
  50.    i, kol: Integer;
  51.    Temp: TRef;
  52.    s: string;
  53. begin
  54.    kol := 0;
  55.    s := Date.Text;
  56.    for i := 1 to length(s) do
  57.       if s[i] = '.' then
  58.          inc(kol);
  59.    if kol <> 2 then
  60.       MessageDlg('Введите дату в формате день.месяц.год', mtError, [mbOK], 0)
  61.    else
  62.    begin
  63.       Inc(ChangeIndex);
  64.       seek(MyFile, ChangeIndex - 1);
  65.       Temp.Topic := Topic.Text;
  66.       Temp.Author := SecName.Text;
  67.       Temp.Str := StrToInt(Str.Text);
  68.       Temp.Date := Date.Text;
  69.       Write(MyFile, Temp);
  70.       Inc(ChangeIndex);
  71.       seek(MyFIle, ChangeIndex - 1);
  72.       for i := n - 1 to FileSize(MyFile) - 2 do
  73.       begin
  74.          seek(MyFile, i + 1);
  75.          Read(MyFIle, temp);
  76.          seek(MyFile, i);
  77.          Write(MyFile, Temp);
  78.       end;
  79.       seek(MyFile, FileSize(myfile));
  80.       truncate(MyFile);
  81.       Reset(MyFile);
  82.       i := 0;
  83.       While not eof(MyFile) do
  84.       begin
  85.          Read(MyFile, Ref[i]);
  86.          Inc(i);
  87.       end;
  88.       n := i;
  89.       Refs.Clear;
  90.       ChangeForm.Hide;
  91.       BaseForm.Show;
  92.    end;
  93. end;
  94.  
  95. procedure TChangeForm.RefsClick(Sender: TObject);
  96. begin
  97.    Save.Visible := True;
  98.    ChangeIndex := Refs.Items.IndexOf(Refs.Text);
  99.    Topic.Text := Ref[ChangeIndex].Topic;
  100.    SecName.Text := Ref[ChangeIndex].Author;
  101.    Str.Text := IntToStr(Ref[ChangeIndex].Str);
  102.    Date.Text := Ref[ChangeIndex].Date;
  103.    Topic.Visible := True;
  104.    SecName.Visible := True;
  105.    Str.Visible := True;
  106.    Date.Visible := True;
  107.    LTopic.Visible := True;
  108.    LSecName.Visible := True;
  109.    LStr.Visible := True;
  110.    LDate.Visible := True;
  111. end;
  112.  
  113. procedure TChangeForm.RefsDropDown(Sender: TObject);
  114. var
  115.    i: Integer;
  116. begin
  117.    Refs.Clear;
  118.    for i := 0 to n - 1 do
  119.       Refs.Items.Add(Ref[i].Topic);
  120. end;
  121.  
  122. procedure TChangeForm.SecNameKeyPress(Sender: TObject; var Key: Char);
  123. const
  124.    Digit: set of Char = ['a'..'z', #8, 'A'..'Z'];
  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 TChangeForm.StrKeyPress(Sender: TObject; var Key: Char);
  134. const
  135.    Digit: set of Char = ['0'..'9', #8];
  136. begin
  137.    with (Sender as TEdit) do
  138.    begin
  139.       if not(Key in Digit) then
  140.          Key := #0;
  141.    end;
  142. end;
  143.  
  144. procedure TChangeForm.DateKeyPress(Sender: TObject; var Key: Char);
  145. const
  146.    Digit: set of Char = ['0'..'9', #8, '.'];
  147. begin
  148.    with (Sender as TEdit) do
  149.    begin
  150.       if not(Key in Digit) then
  151.          Key := #0;
  152.    end;
  153. end;
  154.  
  155. procedure TChangeForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  156. begin
  157.    BaseForm.Show;
  158.    MenuForm.Hide;
  159.    ChangeMenuForm.Hide;
  160.    AddForm.Hide;
  161.    DeleteForm.Hide;
  162.    ChangeForm.Hide;
  163. end;
  164.  
  165. procedure TChangeForm.FormShow(Sender: TObject);
  166. begin
  167.    Refs.Clear;
  168.    Save.Visible := False;
  169.    Topic.Visible := False;
  170.    SecName.Visible := False;
  171.    Str.Visible := False;
  172.    Date.Visible := False;
  173.    LTopic.Visible := False;
  174.    LSecName.Visible := False;
  175.    LStr.Visible := False;
  176.    LDate.Visible := False;
  177. end;
  178.  
  179. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement