概述:我有一个应用程序,我们想要监听/测试事件,理想的是将事件名称传递给存储过程并能够报告事件成功和/或不成功。
问题:事件仅在第一次执行,后续事件不执行。(见通知事件警报)
存储过程:
CREATE PROCEDURE TESTEVENT(EVENTNAME VARCHAR(65))
AS
BEGIN
POST_EVENT(:EVENTNAME);
END;
通知事件警报:
//Note event is only getting excuted the first time
procedure TObjApplicationEvents.NotifyEventAlert(Sender: TObject;
EventName: string; EventCount: Integer; var CancelAlerts: Boolean);
begin
if Assigned(Self.OnPostedEvent) then
Self.OnPostedEvent(Self, Eventname);
end;
事件发布:
procedure TFrmEventProcessingTestLkp.btnTestEventClick(Sender: TObject);
var
c : TCursor;
ae : TObjApplicationEvents;
cq : TCustomQuery;
begin
inherited;
c := Screen.Cursor;
Screen.Cursor := crHourglass;
ae := nil;
cq := nil;
try
try
ae := TObjApplicationEvents.Create;
ae.OnPostedEvent := Self.OnPostedEvent;
cq := TCustomQuery.Create(nil);
cq.StartTransaction;
cq.SetOperationType(cqotStoredProcedure);
cq.SetStoredProcName('TESTEVENT');
cq.Params.CreateParam(ftString, 'EVENTNAME', ptInput);
cq.ParamByName('EVENTNAME').Value := GetRecordColumnValue(cxColEvent.Index);
cq.ExecSQL;
cq.CommitTransaction;
Sleep(1000);
except on e: Exception do
begin
cq.RollBackTransaction;
raise Exception.Create(e.message);
end;
end;
finally
FreeAndNil(ae);
FreeAndNil(cq);
Screen.Cursor:= c;
end;
end;