View Issue Details

IDProjectCategoryView StatusLast Update
0027178LazarusDatabase Componentspublic2019-11-23 23:13
ReporterPetr-K Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.3 (SVN) 
Summary0027178: DBEdit.Free with focus cause SEGV
DescriptionTDBEdit.Destroy first destroys FDatalink and then calls inherited Destroy.
There WMKillFocus is called which use FDatalink.

Attached patch solves this issue.
TagsNo tags attached.
Fixed in Revisionr62288
LazTarget-
Widgetset
Attached Files

Activities

Petr-K

2014-12-17 09:48

reporter  

dbedit.patch (1,359 bytes)   
Index: dbedit.inc
===================================================================
--- dbedit.inc	(revision 46763)
+++ dbedit.inc	(working copy)
@@ -213,20 +213,23 @@
 
   FFocusedDisplay := False;
 
-  if FDatalink.Editing then
+  if Assigned(FDataLink) then
   begin
-    FDatalink.UpdateRecord;
-    //check for Focused before disabling the mask since SetFocus can be called
-    //inside events propagated by WMKillFocus or UpdateRecord
-    if not Focused then
+    if FDatalink.Editing then
     begin
-      DisableMask(FDataLink.Field.DisplayText);
-      //reset the modified flag that is changed after setting the text
-      FDataLink.IsModified := False;
-    end;
-  end
-  else
-    FDatalink.Reset;
+      FDatalink.UpdateRecord;
+      //check for Focused before disabling the mask since SetFocus can be called
+      //inside events propagated by WMKillFocus or UpdateRecord
+      if not Focused then
+      begin
+        DisableMask(FDataLink.Field.DisplayText);
+        //reset the modified flag that is changed after setting the text
+        FDataLink.IsModified := False;
+      end;
+    end
+    else
+      FDatalink.Reset;
+  end;
 end;
 
 procedure TDBEdit.WndProc(var Message: TLMessage);
@@ -265,7 +268,7 @@
 
 destructor TDBEdit.Destroy;
 begin
-  FDataLink.Destroy;
+  FreeAndNil(FDataLink);
   inherited Destroy;
 end;
 
dbedit.patch (1,359 bytes)   

Bart Broersma

2014-12-17 11:27

developer   ~0079862

Wouldn't a check for csDestroying make more sense?

Petr-K

2014-12-17 12:12

reporter  

dbedit1.patch (1,240 bytes)   
Index: dbedit.inc
===================================================================
--- dbedit.inc	(revision 46763)
+++ dbedit.inc	(working copy)
@@ -213,20 +213,23 @@
 
   FFocusedDisplay := False;
 
-  if FDatalink.Editing then
+  if not (csDestroying in ComponentState) then
   begin
-    FDatalink.UpdateRecord;
-    //check for Focused before disabling the mask since SetFocus can be called
-    //inside events propagated by WMKillFocus or UpdateRecord
-    if not Focused then
+    if FDatalink.Editing then
     begin
-      DisableMask(FDataLink.Field.DisplayText);
-      //reset the modified flag that is changed after setting the text
-      FDataLink.IsModified := False;
-    end;
-  end
-  else
-    FDatalink.Reset;
+      FDatalink.UpdateRecord;
+      //check for Focused before disabling the mask since SetFocus can be called
+      //inside events propagated by WMKillFocus or UpdateRecord
+      if not Focused then
+      begin
+        DisableMask(FDataLink.Field.DisplayText);
+        //reset the modified flag that is changed after setting the text
+        FDataLink.IsModified := False;
+      end;
+    end
+    else
+      FDatalink.Reset;
+  end;
 end;
 
 procedure TDBEdit.WndProc(var Message: TLMessage);
dbedit1.patch (1,240 bytes)   

Petr-K

2014-12-17 12:13

reporter   ~0079866

Good idea. I uploaded modified dbedit1.patch

Juha Manninen

2019-11-23 23:13

developer   ~0119471

This was somehow forgotten. I applied a modified version of the patch. Thanks!

Issue History

Date Modified Username Field Change
2014-12-17 09:48 Petr-K New Issue
2014-12-17 09:48 Petr-K File Added: dbedit.patch
2014-12-17 11:27 Bart Broersma Note Added: 0079862
2014-12-17 12:12 Petr-K File Added: dbedit1.patch
2014-12-17 12:13 Petr-K Note Added: 0079866
2019-11-23 23:07 Juha Manninen Assigned To => Juha Manninen
2019-11-23 23:07 Juha Manninen Status new => assigned
2019-11-23 23:13 Juha Manninen Status assigned => resolved
2019-11-23 23:13 Juha Manninen Resolution open => fixed
2019-11-23 23:13 Juha Manninen Fixed in Revision => r62288
2019-11-23 23:13 Juha Manninen LazTarget => -
2019-11-23 23:13 Juha Manninen Note Added: 0119471