[Gambas-user] Karmic sqlite problem.

Doriano Blengino doriano.blengino at ...1909...
Thu Nov 5 15:54:04 CET 2009


Benoît Minisini ha scritto:
>> Benoît Minisini wrote:
>>     
>>>> Here is a program and it do hang when you enable me.width in form1
>>>>
>>>> http://old.nabble.com/file/p26203186/crash-test-0.0.1.tar.gz
>>>> crash-test-0.0.1.tar.gz
>>>>
>>>>
>>>> -----
>>>> Regards R. Stormo
>>>>
>>>>
>>>> My Gambas Community http://gambasforum.tk
>>>>         
>>> Your program is an endless loop into Form_Resize.
>>>
>>> Your form is inside a HBox. So changing the Width triggers a deffered
>>> Resize
>>> event. But as the HBox resizes the form later, the Width changed again to
>>> its
>>> initial value, and all the process starts again forever!
>>>
>>> Changing the size of the form inside its Resize event is a bad idea. What
>>> did
>>> you try to achieve?
>>>       
>> It has worked for a couple of years.  strange that it just arrived then.
>> You say it's a endless loop.?
>>
>>  f1 = NEW Form1(HBox1)
>>  f2 = NEW Form2
>>  f3 = NEW Form1
>>
>> Isn't F1 a new instance of the form also f3 , then it should not be a
>> problem to resize it twice.
>>
>>     
>
> Resizing a form inside its resize event is *always* a bug in the design of 
> your application.
>
> Setting the width property of a form won't raise a Resize event only if the 
> new width is the same as the old width.
>   
...but you can use a global lock variable to avoid the endless loop:

    private resize_dont_reenter as boolean = false

    public sub Form_Resize()
      if resize_dont_reenter then
        resize_dont_reenter = false
        return
      end if

      ' in the same place where you fiddle with the form
      resize_dont_reenter = true
        ... ' do your stuff which will raise the event

    end               

I don't see why it should be a bug to want to resize a form inside its 
resize event handler. If I want to put constraints in the dimensions of 
a form (say, just for fun, "the width of a form should be a multiple of 
32 pixels"), it is logic to place such manipulation in the resize event 
handler, or some place inherent to it. May be that one can object.lock() 
the form, or use a lock variable, or use a flag to defer the 
manipulation perhaps through a timer. But to say "it is an error to 
resize a form at the time the user resizes it" it seems to much to me.

Regards,
Doriano




More information about the User mailing list