向下选中N条
方法1:单击事件写法
procedure TForm3.N24Click(Sender: TObject);
var
Atiao:string;
I: Integer;
//begin
begin
//获取N值
if not InputQuery('输入条数', '需选择条数', Atiao) then
begin
ShowMessage('请输入选择条数N值');
Exit;
end;
//向下选中N条,循环N次修改选中的值为真;
begin
for I := 1 to Atiao.ToInteger do
begin
with frmDataPool.qry需要做的事 do
begin
Edit;
FieldByName('选中').AsBoolean := True;
Post;
Next;
end;
end;
end;
end;
方法2:类写法
unit USelectDownNRec;
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>
/// 向下选中N条 ,循环N次修改选中的值为真;
/// </summary>
type TSelectDownNRec =class
public
class procedure selectnrecord (var SAdq:TADOQuery);
end;
implementation
class procedure TSelectDownNRec.selectnrecord(var SAdq: TADOQuery);
var
Atiao:string;
I: Integer;
begin
//获取N值
if not InputQuery('输入条数', '需选择条数', Atiao) then
begin
ShowMessage('请输入选择条数N值');
Exit;
end;
//向下选中N条,循环N次修改选中的值为真;
begin
for I := 1 to Atiao.ToInteger do
begin
with SAdq do
begin
Edit;
FieldByName('选中').AsBoolean := True;
Post;
Next;
end;
end;
end;
end;
end.
类引用方法:(哪个单元需要使用要先引用定义的类单元:如在uses 语句里面添加 USelectDownNRec;)
然后按下方方法调用即可:
procedure TForm3.N24Click(Sender: TObject);
begin
TSelectDownNRec.selectnrecord(frmDataPool.qry需要做的事);
end;