Creating new variable type ?

I put this in OS X since I found this in MacOSLib.

For a recent project, I had to use CFURL to call a Cocoa declare, but that particular type does not exist natively in Xojo.

However, I noticed that MacOSLib had the type CFURL, and even uses it just like a native type as in :

dim base as CFURL = me.BaseURL

Being able to create new types like that which seem to be usable like other types is a fascinating possibility that could vastly simplify coding.

I tried to understand how this works, but the way it is built into MacOSLib is so arborescent, with internal calls to hundreds of methods and properties, I was unable to really grasp the essential. I see that CFURL is a global class within the CoreFoundation Module, but I got lost trying to understand how a class can take a value directly like a variable, possibly with implicit conversion.

I will appreciate any possible insight.


Read docs about Operator_Convert.

That is nice but it does not seem to allow creating a new type beyond existing ones.

It’s what is used in MacOSLib. If you look at the declare itself the parameter will be a Ptr. Using Operator_Convert, the object, in this case CFURL, returns the pointer to the represented object created in declares. That’s all that is happening, there is no other magic going on behind the scenes. So although it looks like there is a new type created, it is simply the object returning its pointer. Every time a declare is used with an object instance in MacOSLib, Operator_Convert returns the pointer. In this case the same effect would be accomplished if instead of using just the instance you used “” which also returns the pointer. Hopefully that makes sense.

Assuming ‘me’ is a CFURL I don’t see any Operator_Convert going on. CFURL.BaseURL is a computed property that returns a CFURL which is stored in variable base.

CFURL is a class.
CFType is its super class.
CFType has a property called “Handle”, which is of type CFTypeRef structure.
CFTypeRef is a structure, which consists only of one field “value”, which is of type Ptr.

Thank you. I understand better, now.