[Gambas-user] How to use the WITH / END WITH safe
    ron 
    ronstk at ...239...
       
    Thu Apr  8 14:07:13 CEST 2004
    
    
  
May be a silly question
Example : 
WITH hButton
  .Text = Cstr("Cancel" & 1/0 )
END WITH
is equivalent to 
hButton.Text = Cstr( "Cancel" & 1/0 )
It is the bug VB has in my point of view.
The WITH creates a reference to the hButton and allocate memory for it
The END WITH stops the dot reference (.Text) and removes the reference 
and free the memory used for it.
In the case of VB a error leaves the procedure and did
not free the memory. Here for the example forced by divide by zero
In VB you should use a construction like next to trap this miss behavior.
ON Error Goto WithAbort
WITH hButton
  .Text = Cstr("Cancel" & 1/0 )
WithAbort::
' free memory with next END
END WITH
I like to use the WITH a lot for example to set up controls in code.
WITH Columnview1
	.color
	.columns
	.Height
	. the other position and dimensions
END WITH
 It is now easy to change the object name instead  without the WITH
or even use the same code for a stack of ColumnViews
Second pro is you do not need to type the name over and over.
My question is: does gambas free used WITH references on exit of the procedure
 or must I use the same trick as VB needs?
Ron
    
    
More information about the User
mailing list