Strange, it didn't crash here (same version). Are you using Win32?

Anyway, you asked:

> Question #:
>
> Is this correct coding?

(p.s: I removed the spaces before the colon and the question mark  
because it seems ugly)

and my answer is that there is simpler (so better) way to do it.

I don't know if we can speak about "correct coding" if the purpose is  
for testing something specific.


You also posted some code:

   // Toogle the focus ring
   Dim theCanvas As Canvas

   // Compute if the Focus is set to a Canvas
   If Self.Focus IsA Canvas Then
     // Cast Canvas Control who have the Focus
     theCanvas = Canvas(Self.Focus)

     If theCanvas = Me Then
       // Ask the Window to clear the focus
       ClearFocus
     End If

   Else
     // Ask the Canvas to set the focus
     Me.SetFocus

   End If

You may use a variable of type RectControl to avoid calling  
Self.Focus more than once, since you know the focus does not change  
inside your method.

> To clears the Focus from the Canvas, I have to use a Window command  
> - ClearFocus - and to set the Focus to the canvas, I have to use a  
> Canvas command - Me.SetFocus - ; where the code consistency?.

You learnt german, right? (every noun starting with a capital  
letter) ;-)

It may not be inconsistent. Each class is dealing at its level.

Could you imagine a RectControl with a ClearFocus method to clear the  
focus of the window? Does not make sense. Maybe adding a  
RemoveFocusFromMe would make sense, but the concept of removing the  
focus of ANY control that has it would break.

For setting the focus, using self.SetFocus(MyControl) is a bit odd.  
Also, from the API, the focus is set from the control (it's it that  
has the Focus property and, therefore, a way to grab the focus).

So I don't see how you would like to see a more consistent way to  
remove/set the focus.

You also wrote:

> a. Why do I not place the second if group in the first if like in:

Here, I just don't know if you are asking yourself or the ones in the  
list.

The next time, I'll quote a message you posted 5 months ago ;-)

Le 28 févr. 07 à 16:10 Soir, Emile SCHWARZ a écrit:

> Because it crashed (tested right now) REALbasic 2007r1...
>
> Also because I tried using IsA (yesterday)...
>
>
> Thanks,
>
> Emile
>
>
> Date: Tue, 27 Feb 2007 16:26:11 +0100
> From: Arnaud Nicolet <[EMAIL PROTECTED]>
> Subject: Re: The Case of the Canvas Toogle Focus
> To: REALbasic NUG <[email protected]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi,
>
> Why don't you simply write:
>
> if Self.Focus=me then
> ClearFocus
> else
> Me.SetFocus
> end if

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to