60 |
|
{ } |
61 |
|
{************************************************************************} |
62 |
|
unit FBEvents; |
63 |
< |
{$IFDEF MSWINDOWS} |
64 |
< |
{$DEFINE WINDOWS} |
63 |
> |
{$IFDEF MSWINDOWS} |
64 |
> |
{$DEFINE WINDOWS} |
65 |
|
{$ENDIF} |
66 |
|
|
67 |
|
{$IFDEF FPC} |
108 |
|
procedure CancelEvents(Force: boolean = false); virtual; |
109 |
|
procedure EventSignaled; |
110 |
|
function GetIEvents: IEvents; virtual; abstract; |
111 |
< |
procedure ProcessEventCounts; |
111 |
> |
function ProcessEventCounts: boolean; |
112 |
|
public |
113 |
|
const EPB_version1 = 1; |
114 |
|
public |
118 |
|
{IEvents} |
119 |
|
procedure GetEvents(EventNames: TStrings); |
120 |
|
procedure SetEvents(EventNames: TStrings); overload; |
121 |
< |
procedure SetEvents(Event: AnsiString); overload; |
121 |
> |
procedure SetEvents(Event: string); overload; |
122 |
|
procedure Cancel; |
123 |
|
function ExtractEventCounts: TEventCounts; |
124 |
|
function GetAttachment: IAttachment; |
125 |
|
procedure AsyncWaitForEvent(EventHandler: TEventHandler); virtual; abstract; |
126 |
+ |
procedure WaitForEvent; virtual; abstract; |
127 |
|
end; |
128 |
|
|
129 |
|
|
219 |
|
procedure TFBEvents.CreateEventBlock; |
220 |
|
var i: integer; |
221 |
|
P: PByte; |
222 |
+ |
var s: Ansistring; |
223 |
|
begin |
224 |
|
{calculate length of event parameter block, setting initial length to include version |
225 |
|
and counts for each argument} |
226 |
|
|
227 |
+ |
if FEventBuffer <> nil then FreeAndNil(FEventBuffer); |
228 |
+ |
if FResultBuffer <> nil then FreeAndNil(FResultBuffer); |
229 |
+ |
|
230 |
|
FEventBufferLen := 1; |
231 |
|
for i := 0 to FEvents.Count - 1 do |
232 |
< |
FEventBufferLen := FEventBufferLen + length(FEvents[i]) + 1 + sizeof(Long); |
232 |
> |
begin |
233 |
> |
s := FEvents[i]; |
234 |
> |
FEventBufferLen := FEventBufferLen + length(s) + 1 + sizeof(Long); |
235 |
> |
end; |
236 |
|
|
237 |
|
with FFirebirdClientAPI do |
238 |
|
begin |
242 |
|
IBAlloc(FResultBuffer,0,FEventBufferLen); |
243 |
|
if FResultBuffer = nil then |
244 |
|
begin |
245 |
< |
FreeMem(FEventBuffer); |
245 |
> |
FreeAndNil(FEventBuffer); |
246 |
|
Exit; |
247 |
|
end; |
248 |
|
FillChar(FResultBuffer^,FEventBufferLen,0); |
254 |
|
|
255 |
|
for i := 0 to FEvents.Count - 1 do |
256 |
|
begin |
257 |
< |
P^ := Length(FEvents[i]); |
257 |
> |
s := FEvents[i]; |
258 |
> |
P^ := Length(s); |
259 |
|
Inc(P); |
260 |
< |
Move(FEvents[i][1],P^,Length(FEvents[i])); |
261 |
< |
Inc(P,Length(FEvents[i])+sizeof(Long)); |
262 |
< |
FEventCounts[i].EventName := FEvents[i]; |
260 |
> |
Move(s[1],P^,Length(s)); |
261 |
> |
Inc(P,Length(s)+sizeof(Long)); |
262 |
> |
FEventCounts[i].EventName := s; |
263 |
|
end; |
264 |
|
end; |
265 |
|
|
266 |
|
{ for i := 0 to FEventBufferLen - 1 do |
267 |
|
write(Format('%x ', [FEventBuffer[i]])); |
268 |
< |
writeln;} |
268 |
> |
writeln; } |
269 |
|
end; |
270 |
|
|
271 |
|
procedure TFBEvents.CancelEvents(Force: boolean); |
280 |
|
FCriticalSection.Enter; |
281 |
|
try |
282 |
|
if not FInWaitState then Exit; |
283 |
< |
FInWaitState := false; |
275 |
< |
ProcessEventCounts; |
276 |
< |
if assigned(FEventHandler) then |
283 |
> |
if ProcessEventCounts and assigned(FEventHandler) then |
284 |
|
begin |
285 |
|
Handler := FEventHandler; |
286 |
|
FEventHandler := nil; |
287 |
+ |
FInWaitState := false; |
288 |
|
end; |
289 |
|
finally |
290 |
|
FCriticalSection.Leave; |
349 |
|
|
350 |
|
{ProcessEventCounts effectively replaces isc_event_counts} |
351 |
|
|
352 |
< |
procedure TFBEvents.ProcessEventCounts; |
352 |
> |
function TFBEvents.ProcessEventCounts: boolean; |
353 |
|
|
354 |
|
var i: integer; |
355 |
|
P, Q: PByte; |
357 |
|
new_count: Long; |
358 |
|
len: byte; |
359 |
|
begin |
360 |
+ |
Result := false; |
361 |
|
P := FEventBuffer; |
362 |
|
Q := FResultBuffer; |
363 |
|
Inc(P); {skip past version byte} |
374 |
|
new_count := DecodeInteger(Q,sizeof(Long)); |
375 |
|
Inc(Q,sizeof(Long)); |
376 |
|
FEventCounts[i].Count := new_count - initial_count; |
377 |
+ |
if FEventCounts[i].Count > 0 then |
378 |
+ |
Result := true; |
379 |
+ |
// writeln('Event Count[',i,'] = ',FEventCounts[i].Count); |
380 |
|
end; |
381 |
|
Move(FResultBuffer^,FEventBuffer^,FEventBufferLen); |
382 |
|
end; |
431 |
|
end; |
432 |
|
end; |
433 |
|
|
434 |
< |
procedure TFBEvents.SetEvents(Event: AnsiString); |
434 |
> |
procedure TFBEvents.SetEvents(Event: string); |
435 |
|
var S: TStringList; |
436 |
|
begin |
437 |
|
S := TStringList.Create; |