Advertisement
MadCortez

Untitled

Mar 23rd, 2021
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.21 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.     ComboBox1: TComboBox;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Label3: TLabel;
  16.     Label4: TLabel;
  17.     Edit1: TEdit;
  18.     Edit2: TEdit;
  19.     Edit3: TEdit;
  20.     Edit4: TEdit;
  21.     Button1: TButton;
  22.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  23.     procedure ComboBox1DropDown(Sender: TObject);
  24.     procedure ComboBox1Click(Sender: TObject);
  25.     procedure FormShow(Sender: TObject);
  26.     procedure Button1Click(Sender: TObject);
  27.     procedure Edit2KeyPress(Sender: TObject; var Key: Char);
  28.     procedure Edit3KeyPress(Sender: TObject; var Key: Char);
  29.     procedure Edit4KeyPress(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.Button1Click(Sender: TObject);
  49. var
  50.    i, kol: Integer;
  51.    Temp: TRef;
  52.    s: string;
  53. begin
  54.    kol := 0;
  55.    s := Edit4.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 := Edit1.Text;
  66.       Temp.Author := Edit2.Text;
  67.       Temp.Str := StrToInt(Edit3.Text);
  68.       Temp.Date := Edit4.Text;
  69.       Write(MyFile, Temp);
  70.       for i := ChangeIndex to FileSize(MyFile) - 3 do
  71.       begin
  72.          seek(MyFile, i + 1);
  73.          read(MyFile, Temp);
  74.          seek(MyFile, i);
  75.          Write(MyFile, Temp);
  76.       end;
  77.       seek(MyFile, FileSize(MyFile));
  78.       truncate(MyFile);
  79.       Reset(MyFile);
  80.       i := 0;
  81.       While not eof(MyFile) do
  82.       begin
  83.          Read(MyFile, Ref[i]);
  84.          Inc(i);
  85.       end;
  86.       n := i;
  87.       ComboBox1.Clear;
  88.       ChangeForm.Hide;
  89.       BaseForm.Show;
  90.    end;
  91. end;
  92.  
  93. procedure TChangeForm.ComboBox1Click(Sender: TObject);
  94. begin
  95.    Button1.Visible := True;
  96.    ChangeIndex := ComboBox1.Items.IndexOf(ComboBox1.Text);
  97.    Edit1.Text := Ref[ChangeIndex].Topic;
  98.    Edit2.Text := Ref[ChangeIndex].Author;
  99.    Edit3.Text := IntToStr(Ref[ChangeIndex].Str);
  100.    Edit4.Text := Ref[ChangeIndex].Date;
  101.    Edit1.Visible := True;
  102.    Edit2.Visible := True;
  103.    Edit3.Visible := True;
  104.    Edit4.Visible := True;
  105.    Label1.Visible := True;
  106.    Label2.Visible := True;
  107.    Label3.Visible := True;
  108.    Label4.Visible := True;
  109. end;
  110.  
  111. procedure TChangeForm.ComboBox1DropDown(Sender: TObject);
  112. var
  113.    i: Integer;
  114. begin
  115.    ComboBox1.Clear;
  116.    for i := 0 to n - 1 do
  117.       ComboBox1.Items.Add(Ref[i].Topic);
  118. end;
  119.  
  120. procedure TChangeForm.Edit2KeyPress(Sender: TObject; var Key: Char);
  121. const
  122.    Digit: set of Char = ['a'..'z', #8, 'A'..'Z'];
  123. begin
  124.    with (Sender as TEdit) do
  125.    begin
  126.       if not(Key in Digit) then
  127.          Key := #0;
  128.    end;
  129. end;
  130.  
  131. procedure TChangeForm.Edit3KeyPress(Sender: TObject; var Key: Char);
  132. const
  133.    Digit: set of Char = ['0'..'9', #8];
  134. begin
  135.    with (Sender as TEdit) do
  136.    begin
  137.       if not(Key in Digit) then
  138.          Key := #0;
  139.    end;
  140. end;
  141.  
  142. procedure TChangeForm.Edit4KeyPress(Sender: TObject; var Key: Char);
  143. const
  144.    Digit: set of Char = ['0'..'9', #8, '.'];
  145. begin
  146.    with (Sender as TEdit) do
  147.    begin
  148.       if not(Key in Digit) then
  149.          Key := #0;
  150.    end;
  151. end;
  152.  
  153. procedure TChangeForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  154. begin
  155.    BaseForm.Show;
  156.    MenuForm.Hide;
  157.    ChangeMenuForm.Hide;
  158.    AddForm.Hide;
  159.    DeleteForm.Hide;
  160.    ChangeForm.Hide;
  161. end;
  162.  
  163. procedure TChangeForm.FormShow(Sender: TObject);
  164. begin
  165.    ComboBox1.Clear;
  166.    Button1.Visible := False;
  167.    Edit1.Visible := False;
  168.    Edit2.Visible := False;
  169.    Edit3.Visible := False;
  170.    Edit4.Visible := False;
  171.    Label1.Visible := False;
  172.    Label2.Visible := False;
  173.    Label3.Visible := False;
  174.    Label4.Visible := False;
  175. end;
  176.  
  177. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement