gpt4 book ai didi

delphi - 如何从数据集中一次删除两个同名项目?

转载 作者:行者123 更新时间:2023-12-03 19:44:56 25 4
gpt4 key购买 nike

我在Twwgrid中有一个列表,如下所示:


我希望使用如上所示的右键单击弹出菜单立即删除相同的库存(例如,删除两个均为CTN或UNIT的OREO_CHOC_CREAM)。但是现在我只能用下面的代码一一删除,有什么办法解决这个问题吗?

procedure Tfrm1.mniDeleteClick(Sender: TObject);
begin
inherited;
with grdItems.DataSource.DataSet do begin
if (RecordCount <> 0) and (MessageBox( Application.Handle, 'Delete Record ?', 'Confirmation', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2 + MB_APPLMODAL) = IDYES) then
Delete;
end;
end;

最佳答案

我假设数据集是按库存#排序的,否则将无法正常工作。

procedure Tfrm1.DeleteByStockNum();
var
StockN: string;
DataSet: TDataSet;
begin
DataSet := grdItems.DataSource.DataSet;
DataSet.DisableControls;
try
StockN := DataSet.Fields[0].AsString;
//locating the very first record with this stock #
while (not DataSet.BOF) and
(DataSet.Fields[0].AsString = StockN) do
DataSet.Previous;
if DataSet.Fields[0].AsString <> StockN then
//we are one record above
DataSet.Next;
//lets delete all the matching records
while (not DataSet.IsEmpty)
and (DataSet.Fields[0].AsString = StockN) do
DataSet.Delete;
finally
DataSet.EnableControls;
end;
end;


procedure Tfrm1.mniDeleteClick(Sender: TObject);
begin
inherited;
with grdItems.DataSource.DataSet do begin
if (RecordCount <> 0) and (MessageBox( Application.Handle, 'Delete Record ?', 'Confirmation', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2 + MB_APPLMODAL) = IDYES) then
DeleteByStockNum;
end;
end;


请享用。 :)

关于delphi - 如何从数据集中一次删除两个同名项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3827484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com