删除选中记录
方法1:独立事件单独写法
procedure TForm3.N13Click(Sender: TObject);
var
MyAdoq:TADOQuery;
begin
MyAdoq := TADOQuery.Create(nil);
try
MyAdoq.Connection := frmDataPool.ADOConnection1;
with MyAdoq do
begin
SQL.Text := 'DELETE from 需要做的事 where 选中 = true';
ExecSQL;
end;
//防止程序假死
Application.ProcessMessages;
//刷新纪录
frmDataPool.qry需要做的事.Close;
frmDataPool.qry需要做的事.Open;
finally
MyAdoq.Free;
end;
end;
方法2:类写法
unit UDeleteSelectTrue; interface uses FDataPool, Data.DB, Data.Win.ADODB, Vcl.Menus, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids, Clipbrd, Vcl.StdCtrls; type TDeleteSelectTrue = class public class procedure deletetruerecord(var sAdq:TADOQuery); end; implementation class procedure TDeleteSelectTrue.deletetruerecord(var sAdq: TADOQuery); var ABiao: string; begin ABiao:=copy(sAdq.name,4,length(sAdq.name)-3); try with TADOQuery.Create(nil) do begin Connection := frmDataPool.ADOConnection1; if messagedlg('删除选中记录?',mtconfirmation,[mbyes,mbno],0)<>mryes then Abort else begin SQL.Text := 'DELETE FROM ' + ABiao + ' WHERE 选中 = true'; //showmessage(sql.text); ExecSQL; end; end; //防止程序假死 Application.ProcessMessages; //刷新纪录 sAdq.Requery(); finally TADOQuery.Create(nil).Free; end; end; end.
类引用:uses语句中添加类单元名(UDeleteSelectTrue);
procedure TForm3.N13Click(Sender: TObject);
begin
TDeleteSelectTrue.deletetruerecord(frmDataPool.qry需要做的事); //删除选中记录
end;