从Tstring Grid和dataFile中删除记录

时间:2014-12-08 13:44:55

标签: delphi

如何将Tstring网格中的选定行传递给此deleteFromfile过程。前两个过程使我能够删除Tstring网格中的选定行。因此从TString Grid中删除记录。但是记录存储在文件中。我需要从文件中删除记录以及从Tstring网格中删除记录。

procedure DeleteCurrentRow(Grid: TStringGrid);
    var
      i: Integer;
    begin
      for i := Grid.Row to Grid.RowCount - 2 do
        Grid.Rows[i].Assign(Grid.Rows[i + 1]);
      Grid.RowCount := Grid.RowCount - 1;
    end;


    procedure TManageUsersForm.RemoveUserButtonClick(Sender: TObject);

    begin
      UserStringGrid.Options := UserStringGrid.Options + [goEditing];
      UserStringGrid.Options := UserStringGrid.Options + [goRowSelect];
      DeleteCurrentRow(UserStringGrid);
    end;

procedure DeleteFromfile();
begin
  if messagedlg('Are you sure you want to Delete this record?',
  mtconfirmation, [mbYes, mbNo], 0) = mrYes
  then
    begin
      reset (UserFile);
      seek (UserFile, FileSize(UserFile) –1);
      read (UserFile, User);
      seek (UserFile, recordposition);
      write (UserFile, User);
      seek (UserFile, FileSize(UserFile) –1);
      truncate (UserFile);
      closefile (UserFile);
    end
  {endif}
end;

0 个答案:

没有答案