<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:10pt">Hi Bart,<br><br>I did report a Bug like this on <a href="http://bugs.freepascal.org/view.php?id=14041">Lazarus BugTracker</a><span style="text-decoration: underline;"></span><a href="http://bugs.freepascal.org/view.php?id=14041"></a><br><br><div> </div>[]s Daniel<br><br>Conheça o <a rel="nofollow" target="_blank" href="http://acbr.sourceforge.net">Projeto ACBr - Automaçao Comercial Brasil</a><br><a rel="nofollow" target="_blank" href="http://www.djsystem.com.br"><span style="font-weight: bold;">DJSystem</span> a Loja Patrocinadora do ACBr</a><br><div><br></div><div style="font-family: Courier New,courier,monaco,monospace,sans-serif; font-size: 10pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font size="2" face="Tahoma"><hr size="1"><b><span
style="font-weight: bold;">De:</span></b> Bart <bartjunk64@gmail.com><br><b><span style="font-weight: bold;">Para:</span></b> Lazarus mailing list <lazarus@lists.lazarus.freepascal.org><br><b><span style="font-weight: bold;">Enviadas:</span></b> Domingo, 15 de Novembro de 2009 13:49:57<br><b><span style="font-weight: bold;">Assunto:</span></b> [Lazarus] Question about SetFocus in a DoExit method (TMaskEdit related)<br></font><br>Hi there,<br><br>I'm running into a problem with TMaskEdit (I'm trying to maintain maskedit..pp)<br><br>Desired behaviour (as in Delphi):<br>When user leaves the control and validation failes (and the according<br>exception is raised), two things must happen:<br>1. the control must get focus again<br>2. while resetting the focus to the control the value of FTextOnEnter<br>must _not_ be updated (so that Reset resets the control in a state<br>wher no validation is performed upon lossing focus)<br><br>I tried to achieve
this using a boolean FValidationFailed, set in<br>DoExit, and examine this in DoEnter (where FTextOnEnter is set).<br><br>See the code below (my working copy)<br><br>procedure TCustomMaskEdit.DoEnter;<br>begin<br> inherited DoEnter;<br> if isMasked then<br> begin<br> debugln('TCustomMaskEdit.DoEnter: FValidationFailed =<br>',DbgS(FValidationFailed));<br> FCursorPos := GetSelStart;<br> //Only save FTextOnEnter if validation did not fail in last DoExit<br>that occurred<br> if not FValidationFailed then<br> FTextOnEnter := Inherited Text<br> else<br> FValidationFailed := False;<br> <snipped irrelevant code><br>end;<br><br><br><br>procedure TCustomMaskEdit.DoExit;<br>begin<br> debugln('TCustomMaskEdit.DoExit: FValidationFailed =<br>',DbgS(FValidationFailed));<br> //First give OnExit a change to prevent a
EDBEditError<br> inherited DoExit;<br> {$IFNDEF MASKEDIT_NOVALIDATEONEXIT}<br> //Do not validate if FValidationFailed, or risk raising an exception<br>while the previous exception was<br> //not handled, resulting in an application crash<br> if IsMasked and (FTextOnEnter <> Inherited Text) and (not<br>FValidationFailed) then<br> begin<br> //assume failure<br> try<br> //debugln('TCustomMaskedit.DoExit: try ValidateEdit');<br> FValidationFailed := True;<br> ValidateEdit;<br> FValidationFailed := False;<br> finally<br> if FValidationFailed then<br> begin<br> //debugln('TCustomMaskedit.DoExit: Validation failed');<br> SetFocus;<br> SelectAll;<br> end;<br>
end;<br> end;<br> {$ENDIF}<br>end;<br><br>This functions just fine, as long as the user uses the mouse to leave<br>the control, if the user presses Tab things go wrong:<br><br>Here's the sequence of events when using the mouse<br>1. DoExit, FValidationFailed = False<br>2. Default ExceptionHandler kicks in with a showmessage<br>3. DoEnter, FValidationFailed = True<br><br>Now with the user pressing Tab<br>1. DoExit, FValidationFailed = False<br>2. DoEnter, FValidationFailed = True<br>3. Default ExceptionHandler kicks in with a showmessage<br>4. DoEnter, FValidationFailed = False<br><br>In the latter case, the second DoEnter will set FTextOnEnter because<br>FValidationFailed now is False and Reset does not work properly.<br><br>Has anyone of you an idea how to solve this?<br><br>Thanks,<br><br>Bart<br><br>--<br>_______________________________________________<br>Lazarus mailing list<br><a
ymailto="mailto:Lazarus@lists.lazarus.freepascal.org" href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a><br><a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br></div></div>
<!-- cg29.c2.mail.ac4.yahoo.com compressed/chunked Fri Nov 13 01:44:04 PST 2009 -->
</div><br>
<hr size=1>Veja quais são os assuntos do momento no Yahoo! + Buscados: <a href="http://br.rd.yahoo.com/mail/taglines/mail/*http://br.maisbuscados.yahoo.com/">Top 10</a> - <a href="http://br.rd.yahoo.com/mail/taglines/mail/*http://br.maisbuscados.yahoo.com/celebridades/">Celebridades</a> - <a href="http://br.rd.yahoo.com/mail/taglines/mail/*http://br.maisbuscados.yahoo.com/m%C3%BAsica/">Música</a> - <a href="http://br.rd.yahoo.com/mail/taglines/mail/*http://br.maisbuscados.yahoo.com/esportes/">Esportes</a></body></html>