Advertisement
MadCortez

Untitled

Mar 23rd, 2021
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.86 KB | None | 0 0
  1. unit DeleteRef;
  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.   TDeleteForm = class(TForm)
  11.     Refs: TComboBox;
  12.     DeleteButton: TButton;
  13.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  14.     procedure RefsDropDown(Sender: TObject);
  15.     procedure RefsClick(Sender: TObject);
  16.     procedure DeleteButtonClick(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   DeleteForm: TDeleteForm;
  25.   DeleteIndex: Integer;
  26.  
  27. implementation
  28.  
  29. Uses
  30.    Base, ChangeMenu, Add, Menu, Change;
  31.  
  32. {$R *.dfm}
  33.  
  34. procedure TDeleteForm.DeleteButtonClick(Sender: TObject);
  35. var
  36.    i: Integer;
  37.    Temp: TRef;
  38. begin
  39.    seek(MyFile, DeleteIndex - 1);
  40.    for i := DeleteIndex - 1 to FileSize(MyFile) - 2 do
  41.    begin
  42.       seek(MyFile, i + 1);
  43.       read(MyFile, Temp);
  44.       seek(MyFile, i);
  45.       Write(MyFile, Temp);
  46.    end;
  47.    seek(MyFile, FileSize(MyFile) - 1);
  48.    truncate(MyFile);
  49.    Reset(MyFile);
  50.    i := 0;
  51.    While not eof(MyFile) do
  52.    begin
  53.       Read(MyFile, Ref[i]);
  54.       Inc(i);
  55.    end;
  56.    n := i;
  57.    Refs.Clear;
  58.    DeleteForm.Hide;
  59.    BaseForm.Show;
  60. end;
  61.  
  62.  
  63. procedure TDeleteForm.RefsClick(Sender: TObject);
  64. begin
  65.    DeleteButton.Enabled := True;
  66.    DeleteIndex := Refs.Items.IndexOf(Refs.Text) + 1;
  67. end;
  68.  
  69. procedure TDeleteForm.RefsDropDown(Sender: TObject);
  70. var
  71.    i: Integer;
  72. begin
  73.    Refs.Clear;
  74.    for i := 0 to n - 1 do
  75.       Refs.Items.Add(Ref[i].Topic);
  76. end;
  77.  
  78. procedure TDeleteForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  79. begin
  80.    DeleteButton.Enabled := False;
  81.    Refs.Clear;
  82.    BaseForm.Show;
  83.    MenuForm.Hide;
  84.    ChangeMenuForm.Hide;
  85.    AddForm.Hide;
  86.    DeleteForm.Hide;
  87.    ChangeForm.Hide;
  88. end;
  89.  
  90. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement