Type mismatch error with colours

Sonoma 14.5, 2023r4.

I have some code in the Paint event of a DesktopCanvas. If I write it as follows:

if  (specialColourFlg=False)  then
  g.DrawingColor = Self.Window.BackgroundColor
else
  g.DrawingColor = localColour
end if

then it compiles without error. But I want to write it thus:

g.DrawingColor = if  (specialColourFlg=False, Self.Window.BackgroundColor, localColour)

If I do, then this line doesn’t compile; it gets a Type mismatch error, saying:

UsermsgContainer.umCanvas.Paint, line 33
Type mismatch error. Expected class ColorGroup, but got Color
g.DrawingColor = if (specialColourFlg=False, Self.Window.BackgroundColor, localColour)

Perhaps I’m just tired because it’s late, but I really can’t see what is wrong with my trinary if. Any suggestions?

I tried a simple example of this in an empty project with just a canvas and its Paint event, and of course that compiles.

Backgroundcolor is a ColorGroup and localColor is Color. So the if() gets two different types.

1 Like