Graphics is Always Nil after Dim foo As [NEW] Picture([100,100])

Dim MyPict As New Picture(1000, 1000)


Dim MyPict As Picture()

The MyPict.Graphics is always Nil: why ?

To make it not Nil, I have to copy a Picture to it, but it have to have the same size, else MyPict will be resized to the copied Picture.

Sometimes you want to do something simple and you fail :frowning:


Dim MyPict As New Picture(1000, 1000, 32)

is the way to go. I was thinking “That’s many times I do not read the Picture CLass in the LR, then read, then get the anwser. :wink:

Dim MyPict As New Picture(1000, 1000)

It’s not nil here. How are you checking for Nil?

Sorry Greg, this is MyPict.Graphics that is Nil. And the way to avoid that (when I need MyPict.Graphics is to add the depth arg as:

Dim MyPict As New Picture(1000, 1000, 32)

Sorry Emile… but as Greg I cannot duplicate a NIL graphics…
Please illustrate how/why you believe this to be a true statement?

Dim MyPict As New Picture(1000, 1000)
If MyPict.Graphics=Nil Then 
  MsgBox "NIL"
End If

Emile is obviously on PC, where it is necessary to enter the depth by default.

But if I remember right, dimming without depth should raise an exception.

Michel… I just ran the exact same code I posted above on Win10… and it works the same as on macOS

This should not be the case. Creating pictures with a mask using the extra depth parameter is deprecated. The newer version which uses an alpha channel is the preferred way now. Heck, we use the newer version in the IDE project.

I understand. But we don’t know which version Emile is running.

Hey guys, just red the documentation: Dim Foo As Picture(100, 100) does not creates a .Graphics. To get one, you have to add a depth.

If you specify a depth of zero, a picture with no pixel map at all is created, but with a preinitialized Objects property. Use this option for creating vector graphics pictures via the set of Object2D subclasses.

To be sure of what I wrote, try to draw something in graphics as below, and cry :wink:

[code]Dim Foo As Picture(100, 100)

Foo.Graphics.ForeColor = RGB(255,0,0)
Foo.Graphics.Fill Rect 0,0, 50,50[/code]

Guess what happend ?

Also, while I use VirtualBox to run Windows 10 (1903) Pro, I have a Mac Book Pro running El Capitan and this is my primary development environment.

BTW: try the code below without the Depth:

[code] Dim Clip As New Clipboard
Dim Pict As New Picture(Self.Width, Self.Height, 32)

Clip.Picture = Pict

It will not work. The Nil will be on the Self.DrawInto(Pict.Graphics,0,0) line.

At a moment in the past, I started to forget to use (stop using) the Depth parameter and this annoy me, sometimes.

Dim Foo As Picture(100, 100)

is a syntax error, what version of Xojo are you using?

Dim Foo As Picture(100, 100, 0)

returns you a Nil Graphics

Emile, what you are saying may be true for r2015, but not so for r2019 as been demonstrated already.

and specifiing a depth of ZERO is NOT the same and not specifiying one at all

Dim MyPict As New Picture(1000, 1000,0) // this DOES return NIL
Dim MyPict As New Picture(1000, 1000) // this does not
are NOT equivalent statements

[quote][code] Dim Foo As Picture(100, 100)

Foo.Graphics.ForeColor = RGB(255,0,0)
Foo.Graphics.Fill Rect 0,0, 50,50[/code]
Just to be clear, the reason this code fails is not because of the missing depth parameter. It’s because of the missing New keyword when you declare the picture. The thing that is Nil is Foo, not Foo.Graphics.

This is not a valid syntax. It should fire a compile error.

Dim Foo As Picture // Foo is just ref to a picture, it must not have a constructor signature as none is used (and this gets a Nil)

Dim Foo As New Picture(initial, parameters, Here) // It must match one of the constructor’s signatures

Emile should not be able to do that.