View Issue Details

IDProjectCategoryView StatusLast Update
0024134LazarusDatabase Componentspublic2013-03-29 22:01
ReporterDaniel Simões de AlmeidaAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformWindowsOSSevenOS Version64
Product Version1.1 (SVN)Product Build40556 (svn) 
Target VersionFixed in Version1.1 (SVN) 
Summary0024134: TDBedit maskedit verification on Exit, crashes the Application
DescriptionWhen TDBedit has a MaskEdit, the application crashes when exiting TDBedit after the Invalid Mask message is showed...

Lazarus 1.1 from SVN
FPC: 2.7.1 from 2013-03-20
Steps To ReproduceThe attached project application can demonstrate how to reproduce the problem
TagsNo tags attached.
Fixed in Revisionr40660
LazTarget-
WidgetsetWin32/Win64
Attached Files
  • TDBEdit_with_maskedit.zip (65,277 bytes)
  • maskedit.pp.patch (1,085 bytes)
    Index: maskedit.pp
    ===================================================================
    --- maskedit.pp	(revision 40640)
    +++ maskedit.pp	(working copy)
    @@ -1615,14 +1615,16 @@
       {$IFNDEF MASKEDIT_NOVALIDATEONEXIT}
       //Do not validate if FValidationFailed, or risk raising an exception while the previous exception was
       //not handled, resulting in an application crash
    -  if IsMasked and (FTextOnEnter <> Inherited Text) and (not FValidationFailed) then
    +  if IsMasked and (FTextOnEnter <> Inherited Text) then
       begin
         //assume failure
         try
           //debugln('TCustomMaskedit.DoExit: try ValidateEdit');
    -      FValidationFailed := True;
    -      ValidateEdit;
    -      FValidationFailed := False;
    +      if (not FValidationFailed) then
    +      begin
    +        ValidateEdit;
    +        FValidationFailed := False;
    +      end ;
         finally
           if FValidationFailed then
           begin
    @@ -1967,6 +1969,7 @@
         if not TextIsValid(S) then
         begin
           SetCursorPos;
    +      FValidationFailed := True;
           Raise EDBEditError.Create(SMaskEditNoMatch);
         end;
       end;
    
    maskedit.pp.patch (1,085 bytes)

Activities

Daniel Simões de Almeida

2013-03-25 13:55

reporter  

TDBEdit_with_maskedit.zip (65,277 bytes)

Daniel Simões de Almeida

2013-03-25 16:57

reporter  

maskedit.pp.patch (1,085 bytes)
Index: maskedit.pp
===================================================================
--- maskedit.pp	(revision 40640)
+++ maskedit.pp	(working copy)
@@ -1615,14 +1615,16 @@
   {$IFNDEF MASKEDIT_NOVALIDATEONEXIT}
   //Do not validate if FValidationFailed, or risk raising an exception while the previous exception was
   //not handled, resulting in an application crash
-  if IsMasked and (FTextOnEnter <> Inherited Text) and (not FValidationFailed) then
+  if IsMasked and (FTextOnEnter <> Inherited Text) then
   begin
     //assume failure
     try
       //debugln('TCustomMaskedit.DoExit: try ValidateEdit');
-      FValidationFailed := True;
-      ValidateEdit;
-      FValidationFailed := False;
+      if (not FValidationFailed) then
+      begin
+        ValidateEdit;
+        FValidationFailed := False;
+      end ;
     finally
       if FValidationFailed then
       begin
@@ -1967,6 +1969,7 @@
     if not TextIsValid(S) then
     begin
       SetCursorPos;
+      FValidationFailed := True;
       Raise EDBEditError.Create(SMaskEditNoMatch);
     end;
   end;
maskedit.pp.patch (1,085 bytes)

Daniel Simões de Almeida

2013-03-25 16:58

reporter   ~0066554

I attached a suggestion for a Patch

Bart Broersma

2013-03-28 14:26

developer   ~0066604

I'm unclear how this patch would solve it?
The logic behind the original code was to never call ValidateEdit if FValidationFailed = True.
Since ValidateEdit is the only place where the exception is raised.
Your patch (maybe I'm wrong?) does the same but in a diferent place.
Mind you that FValidationFailed will remain True in the original code if validation fails, because this will raise an exception and the next statement (FValidationFailed := False; ) will never be executed.

In your sample program please verify that in the originalmaskedit code FValidationFailed is False when ValidateEdit is called (insert a debugln at the appropriate place).

I cannot test, since I have no database components installed on any of my machines.

Daniel Simões de Almeida

2013-03-28 16:00

reporter   ~0066605

Hi Bart,

Thanks for answering...

The problem is that the procedure TDBEdit.UpdateData do a direct call to TCustomMaskEdit.ValidateEdit... and this cause a EDBEditError.Create(SMaskEditNoMatch)... this exception will be triggers again during the TCustomMaskEdit.DoExit, and this causes the Application crash

Moving the FValidationFailed = True to inside the procedure TCustomMaskEdit.ValidateEdit can prevent the Second Exception to be raised.

Bart Broersma

2013-03-28 18:53

developer   ~0066609

Thanks for the analysis and the patch.
Applied in r40660. Please test and close if OK.

Daniel Simões de Almeida

2013-03-29 22:01

reporter   ~0066628

Fixed... Thank you

Issue History

Date Modified Username Field Change
2013-03-25 13:53 Daniel Simões de Almeida New Issue
2013-03-25 13:55 Daniel Simões de Almeida File Added: TDBEdit_with_maskedit.zip
2013-03-25 16:57 Daniel Simões de Almeida File Added: maskedit.pp.patch
2013-03-25 16:58 Daniel Simões de Almeida Note Added: 0066554
2013-03-28 14:26 Bart Broersma Note Added: 0066604
2013-03-28 16:00 Daniel Simões de Almeida Note Added: 0066605
2013-03-28 18:53 Bart Broersma Fixed in Revision => r40660
2013-03-28 18:53 Bart Broersma LazTarget => -
2013-03-28 18:53 Bart Broersma Note Added: 0066609
2013-03-28 18:53 Bart Broersma Status new => resolved
2013-03-28 18:53 Bart Broersma Fixed in Version => 1.1 (SVN)
2013-03-28 18:53 Bart Broersma Resolution open => fixed
2013-03-28 18:53 Bart Broersma Assigned To => Bart Broersma
2013-03-29 22:01 Daniel Simões de Almeida Note Added: 0066628
2013-03-29 22:01 Daniel Simões de Almeida Status resolved => closed