MouseDown event in canvas class - "Return mDragging <> Nil" ?

Looking in the Canvas Drag Example, the MouseDown event has this:

Return mDragging <> Nil

Does this equal “Return True” if the mDragging object is not nil? And that’s why the MouseDrag and MouseUp events are received?

So any code that says “if this is true…” can be put in this kind of a return statement?

Related, how do DoubleClick and MouseDown cooperate in canvas classes?

What I’m trying to do is mimic the listbox, so if a tile on my canvas is clicked, that tile’s index becomes the “ListIndex” (and a Change Event fires), but I also want to be able to call the DoubleClick event for deleting a tile.

Yes. You can use any expression that resolves to a value of the correct return type. Return mDragging <> Nil is equivalent to Return (mDragging <> Nil), and both mean the same thing as If mDragging <> Nil Then Return True

It may be better to think of it as meaning the same things as

If mDragging <> Nil Then
  Return True
Else
  Return False
End if

Since the original expression will always return a value and the one line IF variation only does a Return if it is True. Since this is likely at the end of the method, it would accomplish the same objective by falling through to the end of the method.

return if(mDragging<>Nil,True,False)

I figured since we were talking about variations :slight_smile:

I actually like variations like that because it eliminates any ambiguity. While I also understand the syntax in the original message, it is not as intuitive to those not familiar with it. (Hence this whole thread.) So your variation retains the one line terseness, it also is verbose enough to make it (hopefully) obvious to the next person. And over the decades I have come to appreciate simple to read and maintain code even if more verbose than absolutely necessary.