Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/Data Aware Controls/TDBEdit    [ Add a report in this area ]  
Report #:  70959   Status: Closed
Data aware controls are not respecting the TDataSource AutoEdit property
Project:  Delphi Build #:  12.0.3210.17555
Version:    12.0 Submitted By:   Paul Hughes
Report Type:  Basic functionality failure Date Reported:  1/28/2009 9:38:40 PM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   267917
Resolution: Fixed (Resolution Comments) Resolved in Build: : 14.0.3513.24210
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 37
Description
When a datasource has it's AutoEdit property set to false, various edit controls (TDBMemo, TDBEdit, etc) are not
respecting
the AutoEdit setting.

With AutoEdit = false:
Upon entering text (which they shouldn't allow you to do without first going into edit mode), they do not put the dataset
into
edit state (as expected) but they do allow you to enter text (not expected). Then, moving focus to another control raises a
'Dataset not in edit or insert mode' exception.

I've tried the attached example code under D2007 and it behaves as expected.

Steps to Reproduce:
Run the attached example and see that you can enter text and get the errors.
Workarounds
None
Attachment
None
Comments

Ludek Stauber at 5/28/2009 5:20:57 AM -
update 3 and 4 of d2009 does not correct this bug!
:(
does somebody have a workaround? (setting the component to readonly is NO workaround, as the readonly could be already used for other purposes...)

Ludek Stauber at 5/29/2009 12:41:02 AM -
found the bug - the CMEnter method was incorrectly modified in d2009 - testing of syslocale.fareast disappeared from source (even if it would NOT disappear, it wouldn't work - in d2009 is everybody living on far east :) )

just comment out the weird

inherited ReadOnly := false

and it will work again.

BTW apparently suffered our far eastern colleagues already years from this bug, but nobody cared about... ??

Mark Edington (Embarcadero) at 10/21/2009 11:58:05 PM -
The following patch can be applied to DBCtrls.pas with the gnu patch.exe utility:

Index: DBCtrls.pas
===================================================================
--- DBCtrls.pas
(revision 19642)
+++ DBCtrls.pas
(revision 19643)
@@ -1788,7 +1788,8 @@
   end;
   case Key of
     ^H, ^V, ^X, #32..High(Char):
-      FDataLink.Edit;
+      if not FDataLink.Edit then
+        Key := #0;
     #27:
       begin
         FDataLink.Reset;
@@ -1915,20 +1916,20 @@

procedure TDBEdit.WMUndo(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited;
end;

procedure TDBEdit.WMPaste(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited
end;

procedure TDBEdit.WMCut(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited;
end;

procedure TDBEdit.CMEnter(var Message: TCMEnter);
@@ -2586,7 +2587,8 @@
   end;
   case Key of
     ^H, ^V, ^X, #32..High(Char):
-      FDataLink.Edit;
+      if not FDataLink.Edit then
+        Key := #0;
     #27:
       begin
         FDataLink.Reset;
@@ -2636,7 +2638,11 @@
     case Message.Msg of
       WM_LBUTTONDOWN:
         if (Style = csSimple) and (ComboWnd <> EditHandle) then
-          if not FDataLink.Edit then Exit;
+          if not FDataLink.Edit then
+            Exit;
+      WM_PASTE, WM_CUT, WM_UNDO:
+         if not FDataLink.Edit then
+           Exit;
     end;
   inherited ComboWndProc(Message, ComboWnd, ComboProc);
end;
@@ -2828,7 +2834,8 @@
   inherited KeyDown(Key, Shift);
   if Key in [VK_PRIOR, VK_NEXT, VK_END, VK_HOME, VK_LEFT, VK_UP,
     VK_RIGHT, VK_DOWN] then
-    if not FDataLink.Edit then Key := 0;
+    if not FDataLink.Edit then
+      Key := 0;
end;

procedure TDBListBox.KeyPress(var Key: Char);
@@ -2836,7 +2843,8 @@
   inherited KeyPress(Key);
   case Key of
     #32..High(Char):
-      if not FDataLink.Edit then Key := #0;
+      if not FDataLink.Edit then
+        Key := #0;
     #27:
       FDataLink.Reset;
   end;
@@ -3144,7 +3152,8 @@
     end;
     case Key of
       ^H, ^I, ^J, ^M, ^V, ^X, #32..High(Char):
-        FDataLink.Edit;
+        if not FDataLink.Edit then
+          Key := #0;
       #27:
         FDataLink.Reset;
     end;
@@ -3311,20 +3320,20 @@

procedure TDBMemo.WMCut(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited;
end;

procedure TDBMemo.WMUndo(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited;
end;

procedure TDBMemo.WMPaste(var Message: TMessage);
begin
-  FDataLink.Edit;
-  inherited;
+  if FDataLink.Edit then
+    inherited;
end;

procedure TDBMemo.CMGetDataLink(var Message: TMessage);
@@ -5768,7 +5777,11 @@
     if (Key = VK_DELETE) or (Key = VK_BACK) or
       ((Key = VK_INSERT) and (ssShift in Shift)) or
       (((Key = Ord('V')) or (Key = Ord('X'))) and (ssCtrl in Shift)) then
+    begin
       BeginEditing;
+      if not FDataLink.Editing then
+        Key := 0;
+    end;
   end;
end;

@@ -5785,7 +5798,11 @@
     end;
     case Key of
       ^H, ^I, ^J, ^M, ^V, ^X, #32..High(Char):
-        BeginEditing;
+        begin
+          BeginEditing;
+          if not FDataLink.Editing then
+            Key := #0;
+        end;
       #27:
         FDataLink.Reset;
     end;
@@ -5987,13 +6004,15 @@
procedure TDBRichEdit.WMCut(var Message: TMessage);
begin
   BeginEditing;
-  inherited;
+  if FDataLink.Editing then
+    inherited;
end;

procedure TDBRichEdit.WMPaste(var Message: TMessage);
begin
   BeginEditing;
-  inherited;
+  if FDataLink.Editing then
+    inherited;
end;

procedure TDBRichEdit.CMGetDataLink(var Message: TMessage);

Mike Kershaw at 2/19/2010 7:42:04 AM -
Hi Mark,

I've implimented the changes above into the DBCtrls.pas file but it hasn't made the fault go away. Am I missing something ese I should be doing afterwards?

Regards,
Mike.

Server Response from: ETNACODE01