For a general introduction, see this thread where Jim gives a great short introduction into declares: https://forum.xojo.com/13244-nssearchfield
I can send you additional stuff if you like to send me your mail address privately.
About your question: NSMinX is a function of the framework, not of a class which is a special case Jim did not cover I believe.
In these cases you need no selector. The declare would rather be
Declare Function NSMinX lib "Foundation.framework" (aRect as NSRectMBS) As CGFloat
[quote=338302:@shao sean]Structure NSRect
X As Single
Y As Single
Width As Single
Height As Single
End Structure[/quote]
As far as I know one should use CGFloat instead of Single for NSRect to be able to compile for both 32Bit and 64Bit:
Structure NSRect
x As CGFloat
y As CGFloat
width As CGFloat
height As CGFloat
End
Also note that some very basic functions in Cocoa/iOS (like NSMakeRect) cannot be used through declares, because these functions are “inlined” when Apple compiles the frameworks (meaning the compiler replaces every function call with the code of the function and then strips the function entirely from the frameworks). You can easily create your own version in Xojo:
Function NSMakeRect(x As CGFloat, y As CGFloat, w As CGFloat, h As CGFloat) As NSRect
Dim rect As NSRect
rect.x = x
rect.y = y
rect.widh = w
rect.height = h
Return rect
End
Oneandahalf years later I wonder: Did that declare ever work?
I need it currently and Xojo will not link it function not found.
Testing back to 2017r2 which is the oldest version I have installed always returned the same error. NSMinX is not a compiler macro Christian, how did you implement it?
@Ulrich Bogun NSMinX and the like are implemented as inline functions so they are not like other functions. Moreover, they are extremely trivial code so you’d better implement it directly in Xojo. You can find the code for those functions in NSGeometry.h in the Foundation.framework.
I’ve heard of these “functions” referenced as Macros before and the way I understand them is that they’re not part of the Foundation framework. I think (although don’t know for sure) they they basically get included in your application automatically when you use them.
Unless it searches right down in to the guts of the Xcode app bundle it might not find it. Norm tells me his BBEdit multi file search set is looking in /Applications/Xcode.app/Developer/Platforms for Xcode 9 and in a similar location for Xcode 10.
@Sam Rowlands The NSMinX and the like are not macros (though the effects are similar) but inline functions. It means that the code they contain is inserted at compilation time where you use them instead of the normal call…return stuff.
Because the code is copied each time you use the inline function, they should be very small functions.
Thats what mislead me into believing they should be available as usual declares. Real macros have a Macro tag in Apples documentation, these dont. Thanks for clearing that up, Stphane! Time for the second green checkmark in this thread.