Advertisement
MadCortez

Untitled

Mar 23rd, 2021
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.85 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: Integer;
  51.    Temp: TRef;
  52. begin
  53.    Inc(ChangeIndex);
  54.    seek(MyFile, ChangeIndex - 1);
  55.    Temp.Topic := Edit1.Text;
  56.    Temp.Author := Edit2.Text;
  57.    Temp.Str := StrToInt(Edit3.Text);
  58.    Temp.Date := Edit4.Text;
  59.    Write(MyFile, Temp);
  60.    for i := ChangeIndex to FileSize(MyFile) - 3 do
  61.    begin
  62.       seek(MyFile, i + 1);
  63.       read(MyFile, Temp);
  64.       seek(MyFile, i);
  65.       Write(MyFile, Temp);
  66.    end;
  67.    seek(MyFile, FileSize(MyFile));
  68.    truncate(MyFile);
  69.    Reset(MyFile);
  70.    i := 0;
  71.    While not eof(MyFile) do
  72.    begin
  73.       Read(MyFile, Ref[i]);
  74.       Inc(i);
  75.    end;
  76.    n := i;
  77.    ComboBox1.Clear;
  78.    ChangeForm.Hide;
  79.    BaseForm.Show;
  80. end;
  81.  
  82. procedure TChangeForm.ComboBox1Click(Sender: TObject);
  83. begin
  84.    Button1.Visible := True;
  85.    ChangeIndex := ComboBox1.Items.IndexOf(ComboBox1.Text);
  86.    Edit1.Text := Ref[ChangeIndex].Topic;
  87.    Edit2.Text := Ref[ChangeIndex].Author;
  88.    Edit3.Text := IntToStr(Ref[ChangeIndex].Str);
  89.    Edit4.Text := Ref[ChangeIndex].Date;
  90.    Edit1.Visible := True;
  91.    Edit2.Visible := True;
  92.    Edit3.Visible := True;
  93.    Edit4.Visible := True;
  94.    Label1.Visible := True;
  95.    Label2.Visible := True;
  96.    Label3.Visible := True;
  97.    Label4.Visible := True;
  98. end;
  99.  
  100. procedure TChangeForm.ComboBox1DropDown(Sender: TObject);
  101. var
  102.    i: Integer;
  103. begin
  104.    ComboBox1.Clear;
  105.    for i := 0 to n - 1 do
  106.       ComboBox1.Items.Add(Ref[i].Topic);
  107. end;
  108.  
  109. procedure TChangeForm.Edit2KeyPress(Sender: TObject; var Key: Char);
  110. const
  111.    Digit: set of Char = ['a'..'z', #8, 'A'..'Z'];
  112. begin
  113.    with (Sender as TEdit) do
  114.    begin
  115.       if not(Key in Digit) then
  116.          Key := #0;
  117.    end;
  118. end;
  119.  
  120. procedure TChangeForm.Edit3KeyPress(Sender: TObject; var Key: Char);
  121. const
  122.    Digit: set of Char = ['0'..'9', #8];
  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.Edit4KeyPress(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.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  143. begin
  144.    BaseForm.Show;
  145.    MenuForm.Hide;
  146.    ChangeMenuForm.Hide;
  147.    AddForm.Hide;
  148.    DeleteForm.Hide;
  149.    ChangeForm.Hide;
  150. end;
  151.  
  152. procedure TChangeForm.FormShow(Sender: TObject);
  153. begin
  154.    ComboBox1.Clear;
  155.    Button1.Visible := False;
  156.    Edit1.Visible := False;
  157.    Edit2.Visible := False;
  158.    Edit3.Visible := False;
  159.    Edit4.Visible := False;
  160.    Label1.Visible := False;
  161.    Label2.Visible := False;
  162.    Label3.Visible := False;
  163.    Label4.Visible := False;
  164. end;
  165.  
  166. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement