"Handle is deprecated. You should use Use Handle with Enums instead"

I’m going through some of my deprecations. How do I fix the above error in the declare:

Dim CGContextHandle as integer = g.Handle(g.HandleTypeCGContextRef)

g is a graphics parameter.

Var CGContextHandle As Ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
1 Like

A better message for messages like that:

“Handle is deprecated. You should use Use Handle with Enums instead”

Could be

Graphics: Handle(Integer) is deprecated. You should use Handle(Graphics.HandleTypes) instead

@Paul_Lefebvre

1 Like

Very good. And how do I make that an integer for the rest of the declare?

if CGContextHandle = NSGraphicsContextCGContext(NSGraphicsContextCurrentContext(NSGraphicsContextClass)) then return false
xojoGraphicsContextAsNSGraphicsContext = NSGraphicsContextWithCGContextFlipped(NSGraphicsContextClass, CGContextHandle, isFlipped)

If you mean CGContextHandle then you possibly have to change your Declare from Integer to Ptr.

Untested: You Declares should return Ptr instead of Integer.

Var CGContextHandle As Ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Var NSGraphicsContextCGContext, NSGraphicsContextCurrentContext, NSGraphicsContextClass, NSGraphicsContextWithCGContextFlipped As Ptr ' How do you init these objects? Declares?
Var xojoGraphicsContextAsNSGraphicsContext As Ptr
Var isFlipped As Boolean

If CGContextHandle = NSGraphicsContextCGContext(NSGraphicsContextCurrentContext(NSGraphicsContextClass)) Then Return False
xojoGraphicsContextAsNSGraphicsContext = NSGraphicsContextWithCGContextFlipped(NSGraphicsContextClass, CGContextHandle, isFlipped)

If redefining the declares aren’t possible for whatever reason…

Var p As Ptr
Var i As Integer

// Cast the value

i = Integer(p)

p = Ptr(i)
1 Like

Thanks, guys. I’ll try your suggestions and will report back.