Generating compilation error...


Suspect I know the answer to this…

I have a canvas control that has to be a minimum of 33 pixels height or it’ll break at runtime with an error. Is there any way to check this at compilation time to give a message rather than getting an error at runtime. Something like this in open event

If me.Height < 33 Then #Pragma Error "Control must be minimum of 33 pixels high" End If

Obviously this won’t work but, hopefully, gives an idea what I’m trying to achieve. Just want to give a better/helpful message to the developer rather than a runtime error.

Any ideas?

You are mixing water and oil here. “Compile time” and “Run-time”. Can’t do it.

Once the compiler find the “#pragma Error” during the compile time, it will raise the compiler error ignoring the run-time code around.

Triggering It should be isolated using compile-time decisions like #If #EndIf, but it’s not your case.

In other environments there is Design-time (for add-ons, plug-ins) and you could interact with the environment an take “kind of” such actions, like after a control resize, do some processing.

Should have been clear - my code was only pseudo code to try and get across what I’m trying to achieve. Obviously, the code won’t work for the reasons you’ve explained.

Ok. I do suspect the answer to your question is: No, you can’t, it must be at run-time. :slight_smile:

There is something you can do.

if me.height < 33 Then #if DebugBuild Msgbox "the zzz canvas must be at least 33 pixels wide at all times!" #EndIf End if

Yep. But you can only check the condition at run-time.

I believe that what he wants to achieve is something near to “design-time” decisions, but at compile-time.

Thanks - that’s what I’m thinking as well though.

Not very nice though, the canvas control has to be minimum 33 pixels. It would be nice to be able to generate a nice compilation error accordingly. As it stands, the first a developer is going to know is when they get an ugly run-time exception.

[quote=105463:@Greg O’Lone]There is something you can do.

if me.height < 33 Then #if DebugBuild Msgbox "the zzz canvas must be at least 33 pixels wide at all times!" #EndIf End if[/quote]

Thanks Greg - may be the best I can do - maybe even tie that into an App.Quit to avoid the runtime error. I haven’t checked feedback but if there’s no way for us to generate our own compilation errors is it worth a feedback request? Is it doable from a Xojo IDE perspective?

You can’t. Control instances on Windows or WebPages don’t “exist” at compile time.

Greg, why he can’t have a 1x1 canvas at run-time?

33 is a weird limit.

I suspect that something in the canvas is drawing a picture which is getting down to 0x0. Is that correct?

If the canvas is being resized at runtime I’d understand the existence thing. I’ve set the Inspector Behaviour to have it’s height to be 33 but if the developer resizes the canvas in the IDE to be 30 then it’s a shame we can’t catch that at compilation. Even if we had Canvas.MinHeight/MinWidth properties, that would be helpful.

And Yep - it’s a drawing thing…

So why not just not draw that piece if it’s going to be 0x0, so it doesn’t crash?

Thanks guys - you guys gave me the clue with the 0x0/1x1 thing. Just needed a bit more defensive programming in my code!

What about a build script that checks the value of .height during the pre-build phase?

That does not solve the problem of a developer putting:

me.width = 5

in the Open event. It’s much better to put some defensive code in there to prevent the exception.