//代码来自官方论坛
type TUniSqlMonitorEx = class(TUniSqlMonitor) private FExecuteDuration: Cardinal; FFinalEvent: Boolean; protected procedure InternalSQLExecute(Obj: TObject; const SQL: string; Params: TDAParams; const Caption: string; BeforeEvent: boolean; var MessageID: Cardinal); override; public property ExecuteDuration: Cardinal read FExecuteDuration; Property IsFinalEvent: Boolean read FFinalEvent; end; TForm1 = class(TForm) UniConnection1: TUniConnection; UniQuery1: TUniQuery; OracleUniProvider1: TOracleUniProvider; procedure FormCreate(Sender: TObject); private UniSQLMonitor: TUniSqlMonitorEx; procedure onSQL(Sender: TObject; Text: String; Flag: TDATraceFlag); { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TUniSqlMonitorEx } procedure TUniSqlMonitorEx.InternalSQLExecute(Obj: TObject; const SQL: string; Params: TDAParams; const Caption: string; BeforeEvent: boolean; var MessageID: Cardinal); begin if BeforeEvent then begin FFinalEvent := False; FExecuteDuration := GetTickCount; end; inherited; if not BeforeEvent then begin FFinalEvent := True; FExecuteDuration := (GetTickCount - FExecuteDuration); FOnSQLEvent(Obj, SQL, tfQExecute); end; end; procedure TForm1.FormCreate(Sender: TObject); begin UniSQLMonitor := TUniSqlMonitorEx.Create(Application.Owner); UniSQLMonitor.OnSQL := Self.onSQL; UniQuery1.Execute; end;
procedure TForm1.onSQL(Sender: TObject; Text: String; Flag: TDATraceFlag); begin if (Sender is TUniQuery) and (Flag = tfQExecute) then begin if UniSQLMonitor.IsFinalEvent then ShowMessage(FloatToStr(UniSQLMonitor.ExecuteDuration / 100)) else FCurrentSQL := Text; end else if (Flag = tfError) then ShowMessage(FCurrentSQL + ', Error:' + Text); end;
标签:begin,end,Sender,UniSQLMonitor,TObject,耗时,procedure,SQL,TUniSQLMonitor From: https://www.cnblogs.com/sdlz/p/16968858.html