这是我以前的程序里的一段代码, 完成的任务是将DBBRID的多选行一次删除
var tempBookMark : TbookMark;
begin
If dbgrid1.SelectedRows.Count > 1 Then s := '真的要删除这些记录?'
If application.MessageBox(pchar(s), 'CVSC--多媒体光盘检索播放', mb_iconinformation + mb_YesNo) = IdYes Then
Begin
i := 0;
DBGrid1.Datasource.Dataset.DisableControls;
While i <= dbgrid1.SelectedRows.Count - 1 Do
Begin
DBGrid1.Datasource.Dataset.Bookmark := dbgrid1.SelectedRows.Items; //重要的在这里,取得BOOKMARK
TempBookmark := DBGrid1.Datasource.Dataset.GetBookmark;
DBGrid1.Datasource.Dataset.GotoBookmark(TempBookmark);
qry_del.ParamByName('param1').AsInteger := Dbgrid1.DataSource.DataSet.fieldbyname('id').AsInteger;
qry_del.Prepare;
qry_del.ExecSQL;
DBGrid1.Datasource.Dataset.FreeBookmark(TempBookmark); //释放BOOKMARK
inc(i); //下一个选择记录
End;
DBGrid1.Datasource.Dataset.EnableControls;
End;
end;