关于删除当前记录的问题(100分)

  • 主题发起人 主题发起人 royhgf
  • 开始时间 开始时间
R

royhgf

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,在三层结构中,怎样实现删除当前选中的记录?有代码参考吗?该表中每个FIELD都不是唯一的.
 
使用DBGrid中的SelectIndex 和PopupMenu1结合,先在DBGrid中显示,再通过右键选择删除。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, ExtCtrls, Menus, DB;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Panel1: TPanel;
Button1: TButton;
PopupMenu1: TPopupMenu;
Del1: TMenuItem;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure DBGrid1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure Add1Click(Sender: TObject);
procedure Del1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
procedure DeleteRS(DataSet: TDataSet);
implementation
uses UDM;
{$R *.dfm}
procedure DeleteRS(DataSet: TDataSet);
begin
try
with DataSetdo
begin
if not IsEmpty then
Delete;
end;
except
Abort;
end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
if not DM.dstData.Active then
DM.dstData.Open;
end;

procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if DM.dstData.Active then
DM.dstData.Close;
end;

procedure TForm1.DBGrid1KeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
var
LastEditCol:integer;
begin
LastEditCol:=DbGrid1.SelectedIndex;
if LastEditCol <>2 then
exit;//让浮动式菜单只对第二列起作用
if(Key=VK_RETURN)//VK_***是您的热键的虚键值
then
PopupMenu1.Popup(336,222);//336,222浮动式菜单显示的位置
end;

procedure TForm1.Add1Click(Sender: TObject);
begin
with DBGrid1.DataSource.DataSetdo
begin
AppendRS(DBGrid1.DataSource.DataSet);
end;
end;

procedure TForm1.Del1Click(Sender: TObject);
begin
with DBGrid1.DataSource.DataSetdo
begin
if DBGrid1.SelectedIndex <> 0 then
if not IsEmpty then
begin
DeleteRS(DBGrid1.DataSource.DataSet);
end;
end;
end;

end.
 
同意楼上的
先把纪录都显示出来,配合快捷键,删除
 
接受答案了.
 
后退
顶部