ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBEvents.pas
(Generate patch)

Comparing ibx/branches/udr/client/FBEvents.pas (file contents):
Revision 379 by tony, Mon Jan 10 10:08:03 2022 UTC vs.
Revision 381 by tony, Sat Jan 15 00:06:22 2022 UTC

# Line 60 | Line 60
60   {                                                                        }
61   {************************************************************************}
62   unit FBEvents;
63 < {$IFDEF MSWINDOWS}
64 < {$DEFINE WINDOWS}
63 > {$IFDEF MSWINDOWS}
64 > {$DEFINE WINDOWS}
65   {$ENDIF}
66  
67   {$IFDEF FPC}
# Line 108 | Line 108 | type
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
# Line 118 | Line 118 | type
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  
# Line 218 | Line 219 | SLONG API_ROUTINE_VARARG isc_event_block
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
# Line 234 | Line 242 | 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);
# Line 246 | Line 254 | begin
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);
# Line 271 | Line 280 | begin
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;
# Line 341 | Line 349 | void API_ROUTINE isc_event_counts(ULONG*
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;
# Line 349 | Line 357 | var i: integer;
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}
# Line 365 | Line 374 | begin
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;
# Line 419 | Line 431 | begin
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines