Author Topic: DoExit is called before form is shown, why?  (Read 3508 times)


  • Hero Member
  • *****
  • Posts: 3808
    • Bart en Mariska's Webstek
DoExit is called before form is shown, why?
« on: December 28, 2008, 10:33:21 pm »

In the MaskEdit unit I'm working on, I' ve overriden the DoExit procedure, because this is where the ValidateEdit occurs.

Code: [Select]
    procedure DoExit; override;

procedure TCustomMaskEdit.DoExit;
  //First give OnExit a change to prevent a EDBEditError
  inherited DoExit;

Now there is a problem.
If you drop a TMaskEdit on a form, set the mask and set the text to something that will not validate (e.g leave text empty), then an exception is raised as soon as you start the program en the program is killed, you never get to see the form.
If you set the mask at runtime and then set an invalid text, no exception is raised until the user (enters and) leaves the control (this is as it should be).

From the backtrace I can see that DoExit is called.
This happens after the form's OnFromCreate, OnFormShow and OnActivate event.
It seems that the control somehow looses focus in the create --> "actually show on the screen" process

This (raising the exception at this stage) is unwanted behaviour, and i'm not sure how to prevent it.
I tried checking for csLoading in ComponentState
( if not (csLoading in ComponentState) then ) , but it is not.

What check should I perform in order to not call ValidateEdit in this case?
I'm kind of stuck here.




TinyPortal © 2005-2018