[Gambas-user] Gambas IDE FOptions.class

Benoît Minisini gambas at ...1...
Thu Feb 27 15:58:54 CET 2003


Le Jeudi 27 Février 2003 12:16, R.Hansen a écrit :
> at the first, Thanks to Benoit!! Really a nice work.
>
> I found a trivial eror in the gambas ide: I like my own editor colors
>
> :-)) but if i changed any color, gambas crashed. The problem was
>
> SetColor(Last, Dialog.Color). At this time it looks that LAST is not the
> Label but a Timer or an other Control,
>
> I have changed the code in the FOptions.class as followed:
>
> PUBLIC SUB lblColor_MouseUp(X AS Integer, Y AS Integer, Button AS
> Integer)
>   ' ** start RH
>   DIM hCtrl AS Control
>   DIM iIndex AS Integer
>   iIndex = LAST.Tag
>   ' ** end RH
>
>   LAST.Border = Border.Raised
>
>   IF X >= 0 AND Y >= 0 AND X < LAST.W AND Y < LAST.H THEN
>
>     Dialog.Color = LAST.Background
>     IF Dialog.SelectColor() THEN RETURN
>
>     ' ** start RH
>
>     FOR EACH hCtrl IN svwColor.Children
>
>       IF hCtrl.Tag = iIndex THEN
>         SetColor(hCtrl, Dialog.Color, TRUE)
>       ENDIF
>
>     NEXT
>
>     'SetColor(Last, Dialog.Color)
>
>    ' ** end rh
>
>   ENDIF
>
> END
>
> It's working but in my oppinion it must give another way without FOR
> EACH.
> How can i address the Label directly?
>
> svwColor.Children(iIndex) dont work
> svwColor.lblColor(iIndex) dont work
> lblColor(iIndex) dont work
>
> What is my  error in reasoning??
>
> Regards,
>

Hi M. Hansen,

You are right, this is a bug. The problem was the use of the LAST instruction 
just before a call to Dialog.SelectColor(). 

The LAST instruction is valid until a call to the event loop... And during the 
color dialog call, the Timer used for animating the mascot wakes up, and 
modifies the value of LAST !

So the fix is to simply put LAST into a local variable at the beginning of the 
event handler, and to use it, instead of using LAST each time.

It is not necessary to use the Tag property to identify the control as you 
did. A direct reference is sufficient.

Here is the result:

-------
PUBLIC SUB lblColor_MouseUp(X AS Integer, Y AS Integer, Button AS Integer)

  DIM hCtrl AS Label
  
  hCtrl = LAST

  hCtrl.Border = Border.Raised
  
  IF X >= 0 AND Y >= 0 AND X < hCtrl.W AND Y < hCtrl.H THEN
    
    Dialog.Color = hCtrl.Background
    IF Dialog.SelectColor() THEN RETURN
    SetColor(hCtrl, Dialog.Color)
    
  ENDIF

END
-------

Regards,

-- 
Benoît Minisini
mailto:gambas at ...1...




More information about the User mailing list