方法一:类实现
unit USelectAll; 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; /// <summary> /// 全选更新所有记录选中值为1 /// </summary> type TSeleteAll=class public class procedure selectAllRecord (var sAqry:TADOQuery); end; implementation uses 日常管理助手, UInitializeDatabaseAdoSqlApi; class procedure TSeleteAll.selectAllRecord(var sAqry:TADOQuery); var SBiao: string; begin SBiao:=copy(sAqry.name,4,length(sAqry.name)-3); with sAqry do begin Close; SQL.Text :='UPDATE ' + SBiao + ' SET 选中 = 1'; ExecSQL; end; //防止程序假死 // Application.ProcessMessages; // //刷新下显示 // with sAqry do // begin // Close; // SQL.Text :='select * from ' + SBiao ; // Open; // end; TInitializeDatabaseAdoSqlApi.accessAdoToSql(sAqry); end; end.
引用类,所需要用的单元中uses语句里添加该引用类单元名;
procedure TForm3.N8Click(Sender: TObject);
begin
TSeleteAll.selectAllRecord(frmDataPool.qry需要做的事); //全选记录 ,更改选中列为1
end;
方法2:单击事件写法
procedure TForm3.N8Click(Sender: TObject); begin with frmDataPool.qry需要做的事 do begin Close; SQL.Text :='UPDATE 需要做的事 SET 选中 = 1'; ExecSQL; end; //防止程序假死 // Application.ProcessMessages; // //刷新下显示 // with sAqry do // begin // Close; // SQL.Text :='select * from ' + SBiao ; // Open; // end; TInitializeDatabaseAdoSqlApi.accessAdoToSql(frmDataPool.qry需要做的事); end;