View Issue Details

IDProjectCategoryView StatusLast Update
0038007Lazarus CCRrxpublic2020-10-28 22:37
ReporterMichal Gawrycki Assigned ToLagunov Aleksey  
PrioritynormalSeverityminorReproducibilityhave not tried
Status assignedResolutionopen 
Summary0038007: RxDBGrid - Dataset events are not restored
DescriptionTRxDBGrid uses its own Dataset event handlers (OnFilterRecord, BeforeDelete, BeforePost, OnDeleteError, OnPostError). After changing Dataset in the DataSource connected to the TRxDBGrid, event handlers are not restored and may cause AV errors or other problems.
TagsNo tags attached.
Widgetset
Attached Files

Activities

Michal Gawrycki

2020-10-28 22:37

reporter  

test-rxdbgridds.zip (56,096 bytes)
rxdbgriddsev.patch (1,876 bytes)   
Index: trunk/rxdb/rxdbgrid.pas
===================================================================
--- trunk/rxdb/rxdbgrid.pas	(revision 7776)
+++ trunk/rxdb/rxdbgrid.pas	(working copy)
@@ -823,6 +823,8 @@
     //Group data suppert
     FGroupItems:TColumnGroupItems;
 
+    FLastDataset: TDataSet;
+
     procedure DoCreateJMenu;
     function GetColumns: TRxDbGridColumns;
     function GetFooterColor: TColor;
@@ -4808,6 +4810,7 @@
       FSortEngine := RxDBGridSortEngineList.Objects[Pos] as TRxDBGridSortEngine
     else
       FSortEngine := nil;
+    FLastDataset := DataSource.DataSet;
   end;
 
   inherited LinkActive(Value);
@@ -4825,6 +4828,8 @@
 end;
 
 procedure TRxDBGrid.SetDBHandlers(Value: boolean);
+var
+  DS: TDataSet = nil;
 begin
    if Value then
   begin
@@ -4863,16 +4868,24 @@
   else
   begin
     if Assigned(DataSource) and Assigned(DataSource.DataSet) then
+      DS := DataSource.DataSet
+    else
+      if Assigned(FLastDataset) then
+      begin
+        DS := FLastDataset;
+        FLastDataset := nil;
+      end;
+    if Assigned(DS) then
     begin
-      DataSource.DataSet.OnFilterRecord := F_EventOnFilterRec;
+      DS.OnFilterRecord := F_EventOnFilterRec;
       F_EventOnFilterRec := nil;
-      DataSource.DataSet.BeforeDelete := F_EventOnBeforeDelete;
+      DS.BeforeDelete := F_EventOnBeforeDelete;
       F_EventOnBeforeDelete := nil;
-      DataSource.DataSet.BeforePost := F_EventOnBeforePost;
+      DS.BeforePost := F_EventOnBeforePost;
       F_EventOnBeforePost := nil;
-      DataSource.DataSet.OnDeleteError := F_EventOnDeleteError;
+      DS.OnDeleteError := F_EventOnDeleteError;
       F_EventOnDeleteError := nil;
-      DataSource.DataSet.OnPostError := F_EventOnPostError;
+      DS.OnPostError := F_EventOnPostError;
       F_EventOnPostError := nil;
       if rdgFilter in OptionsRx then
       begin
rxdbgriddsev.patch (1,876 bytes)   

Issue History

Date Modified Username Field Change
2020-10-28 22:37 Michal Gawrycki New Issue
2020-10-28 22:37 Michal Gawrycki Status new => assigned
2020-10-28 22:37 Michal Gawrycki Assigned To => Lagunov Aleksey
2020-10-28 22:37 Michal Gawrycki File Added: test-rxdbgridds.zip
2020-10-28 22:37 Michal Gawrycki File Added: rxdbgriddsev.patch