Hi, I'm puzzled by some behaviour of the interpreter when objects raise events from their constructors.
The following big block of text just gives the rationale of my question. I think what I'm doing is not too strange. There is a short demonstration project attached. In my real project I want to implement a TextBox with a ToolButton next to it. This thing has a Validate event and should it be Stop Event'd by the user, this counts as invalid input. The validity of the input is reflected by the ToolButton's Picture. The user can specify a message which is dis- played as a Balloon over the ToolButton after the Button was clicked, explaining why the input is invalid. This is done in the following manner: FValidateBox is a Form class which handles all the logic. On top of that is ValidateBox.class which keeps an internal FValidateBox. If that FValidateBox raises its Validate event, ValidateBox forwards it to the user and redirects any Stop Event back to the FValidateBox to evaluate. This works, except that I also want to force an initial validation of the empty TextBox to initialise the ToolButton's Picture correctly (the question is here: does the user accept the empty string?). So I write in the constructor of ValidateBox.class: Inherits UserControl Private $frmControl As FValidateBox Public Sub _new() $frmControl = New FValidateBox(Me) As "Control" ' Call the Change handler of the TextBox which initiates the validation ' process by raising $frmControl's Validate event. $frmControl.txtInput_Change() End I noticed that in this scenario, the event raised by $frmControl does not reach the Control_Validate() handler in ValidateBox.class and therefore the validation process gets a false positive "correct" answer since nobody had a chance to Stop Event. [ As a workaround, I think I can use a Timer with short delay, despite its ugliness. But I'm curious about the reason. ] Is there a limitation, about raising events from constructors, I don't know of? Also note how, in the demonstration project, I can very well initiate the validation procedure just after the constructor finished. Regards, Tobi -- "There's an old saying: Don't change anything... ever!" -- Mr. Monk
constructor-event-0.0.1.tar.gz
Description: Binary data
------------------------------------------------------------------------------
_______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user