看完下面代码,请记得给分哦。===============unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, DBClient;type _RDataSetEvent = record DataSet: TDataSet
AfterInsert:TDataSetNotifyEvent
end
ArrEvent=Array of _RDataSetEvent
TForm1 = class(TForm) procedure FormCreate(Sender: TObject)
private FEvent:ArrEvent
procedure DoOldAfterInsert(DataSet: TDataSet)
procedure MyAfterInsert(DataSet: TDataSet)
public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DoOldAfterInsert(DataSet: TDataSet);var I:Integer;begin for I:=Low(FEvent) to High(FEvent) do if FEvent.DataSet=DataSet then begin FEvent.AfterInsert(DataSet)
Break
end;end;procedure TForm1.FormCreate(Sender: TObject);var I,H:Integer;begin For I:=0 to Self.ComponentCount-1 do begin if not (Self.Components Is TDataSet) then Continue
if not Assigned( TDataSet(Self.Components).AfterInsert) then Continue
SetLength(FEvent,Length(FEvent)+1)
H:=High(FEvent)
//保存原先事件 FEvent[H].DataSet:= TDataSet(Self.Components)
FEvent[H].AfterInsert := TDataSet(Self.Components).AfterInsert
//更改事件为当前单元中定义的事件 TDataSet(Self.Components).AfterInsert := MyAfterInsert
end;end;procedure TForm1.MyAfterInsert(DataSet: TDataSet);begin ...你的代码... DoOldAfterInsert(DataSet)
//执行原先的AdterInsert事件end;end.