Another declare question.
I have a method returning a Ptr like this one:
Function resultAtIndex(index as integer) As Ptr
declare function resultAtIndex lib "Cocoa" selector "resultAtIndex:" (class_id as ptr, index as integer) as Ptr
return resultAtIndex(self, index)
This is a methond from NSMetadataQuery returning a NSMetadataItem.
Now I have a custom class “NSMetadataItem” and I want to assign the returned Ptr to that class.
Unfortunately it does not work just using
dim NSMetadataItemRef as NSMetadataItem = me.resultAtIndex(index)
and I had no success via casting or what ever I tried (I even looked at the help page for Ptr!).
Any idea how to give the returned Ptr the proper type?
A Ptr is a Ptr is a Ptr.
The only thing you could do is wrap the Ptr in your NSMetadataItem class, for example via a Constructor with a Ptr as parameter. Then you can do:
Dim NSMetadataItemRef As New NSMetadataItem(Me.resultAtIndex(index))
This is in exactly what I want. Unfortunately I habe currently no idea how i can do this…
Can you give me an example?
Private Property mPtr As Ptr
Sub Constructor(p As Ptr)
mPtr = p
Ah, now I see what you mean. This is of course always possible but not wat I want here.
The returned Ptr is in fact a pointer to a NSMetadataItem instance. So I want to tell Xojo that. Any other idea?
You can’t tell Xojo that beyond doing as Eli suggested. That’s exactly how it is handled in MacOSLib and iOSKit and other libs…
Oh I see.
So that is the way to proceed. I thought there would be a easier way to cast a Ptr to any class instance which would be handy for declare usage.
Thanks for your help.