Draw throwing Error

This is an older project I am updating. I looked in the documentation and I can’t see an issue with my code.

I have a Canvas which has a super class with several methods in it. I have updated most of the code to handle graphics and drawing but I am stumped. In my Draw method the first line throws an error but the code looks right. The method has a g as graphics parameter.

Any ideas?

DRAW METHOD
g.ForeColor = &c000000
g.FillRect 0,0,g.Width,g.Height

if Image <> nil then

dim w as integer = m_oBaseView.Width
dim h as integer = m_oBaseView.Height

etc.

What error do you get?

Trying to draw onto a canvas outside of the Paint event?

This would probably happen if this method was called like this:

call   doSomethingTo ( Mywindows.canvas1.graphics)

I get an NilObjectException which I capture that occurs in the Draw method. G returns NIL for some reason.

This only happens at RUNTIME, not while I run the code to test.

In the PAINT event I have draw (g)

g being a parameter

Andrew, I tried that and it was no help. I thought the same thing, maybe the way the color call was formatted.

you get g as Graphics in Picture.Graphics or in the Paint Event
color should be DrawingColor in 2019r3

Markus changing the code still throws the error:

Past
g.ForeColor = &c000000
g.FillRectangle 0,0,g.Width,g.Height

NOW
g.DrawingColor = &c000000
g.FillRectangle 0,0,g.Width,g.Height

Check the callstack on error to find where its being called from with nil

Failing that rename draw to draw2 and compile to see if theres a call coming from outside a paint as you might have done so in some code that only runs at release time