[Lazarus] Res: Question about SetFocus in a DoExit method (TMaskEdit related)
Daniel Simoes de Ameida
dopidaniel at yahoo.com.br
Mon Nov 16 11:10:55 CET 2009
Hi Bart,
I did report a Bug like this on Lazarus BugTracker
[]s Daniel
Conheça o Projeto ACBr - Automaçao Comercial Brasil
DJSystem a Loja Patrocinadora do ACBr
________________________________
De: Bart <bartjunk64 at gmail.com>
Para: Lazarus mailing list <lazarus at lists.lazarus.freepascal.org>
Enviadas: Domingo, 15 de Novembro de 2009 13:49:57
Assunto: [Lazarus] Question about SetFocus in a DoExit method (TMaskEdit related)
Hi there,
I'm running into a problem with TMaskEdit (I'm trying to maintain maskedit..pp)
Desired behaviour (as in Delphi):
When user leaves the control and validation failes (and the according
exception is raised), two things must happen:
1. the control must get focus again
2. while resetting the focus to the control the value of FTextOnEnter
must _not_ be updated (so that Reset resets the control in a state
wher no validation is performed upon lossing focus)
I tried to achieve this using a boolean FValidationFailed, set in
DoExit, and examine this in DoEnter (where FTextOnEnter is set).
See the code below (my working copy)
procedure TCustomMaskEdit.DoEnter;
begin
inherited DoEnter;
if isMasked then
begin
debugln('TCustomMaskEdit.DoEnter: FValidationFailed =
',DbgS(FValidationFailed));
FCursorPos := GetSelStart;
//Only save FTextOnEnter if validation did not fail in last DoExit
that occurred
if not FValidationFailed then
FTextOnEnter := Inherited Text
else
FValidationFailed := False;
<snipped irrelevant code>
end;
procedure TCustomMaskEdit.DoExit;
begin
debugln('TCustomMaskEdit.DoExit: FValidationFailed =
',DbgS(FValidationFailed));
//First give OnExit a change to prevent a EDBEditError
inherited DoExit;
{$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
begin
//assume failure
try
//debugln('TCustomMaskedit.DoExit: try ValidateEdit');
FValidationFailed := True;
ValidateEdit;
FValidationFailed := False;
finally
if FValidationFailed then
begin
//debugln('TCustomMaskedit.DoExit: Validation failed');
SetFocus;
SelectAll;
end;
end;
end;
{$ENDIF}
end;
This functions just fine, as long as the user uses the mouse to leave
the control, if the user presses Tab things go wrong:
Here's the sequence of events when using the mouse
1. DoExit, FValidationFailed = False
2. Default ExceptionHandler kicks in with a showmessage
3. DoEnter, FValidationFailed = True
Now with the user pressing Tab
1. DoExit, FValidationFailed = False
2. DoEnter, FValidationFailed = True
3. Default ExceptionHandler kicks in with a showmessage
4. DoEnter, FValidationFailed = False
In the latter case, the second DoEnter will set FTextOnEnter because
FValidationFailed now is False and Reset does not work properly.
Has anyone of you an idea how to solve this?
Thanks,
Bart
--
_______________________________________________
Lazarus mailing list
Lazarus at lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20091116/ca618cea/attachment-0004.html>
More information about the Lazarus
mailing list