Hi Emile.
I’m looking at that now.
Thanks for the referral.
Regards
Hi Emile.
I’m looking at that now.
Thanks for the referral.
Regards
Hi Emile.
I downloaded the macOSLib you suggested, and when I run it, I get the following. And it fails.
and
Any idea why? I checked my API, and it looks correct.
Regards
What do you mean? That the Xojo declare is named CenterWindow but API call goes to center?
Maybe a good chance to explain some confusing basics, also for @Michael_Cebasek:
Basically a declare means you create a CPU jump to an external piece of code, in most cases forwarding one or several input parameters and sometimes returning some variables too. What you need to know to do so is of course the memory address of that (method|function|property|…)
This is an address that is x bytes away from the beginning of a library.
It would be extremely cumbersome if we would have to handle these addresses by their jump distance value (x), and almost impossible to handle a new revision of that API where addresses have changed.
So systems are handling this by giving names to these jump addresses.
For all pure C or C++ libraries, this address is, ehm, addressed by the String that follows the extended Declare keyword:
Declare Sub TheMethodIWantToJumpTo lib "APIlibrary"…
would be the way to create a jump to an API function TheMethodIWantToJumpTo in the library/framework “APIlibary”, and it is used by this identifier string:
TheMethodIWantToJumpTo
It should be noted that you must use the exact wording you find in the docs including capitalisation.
But what if the API symbol equals a protected Xojo keyword, let’s say Dictionary?
You add an Alias String to the declare:
Declare Function Dictionary lib "APIlibrary" Alias "APIDictionary" …
and call the method by that Alias symbol instead.
The lib string is always the name/url of the library.
On macOS and iOS, all GUI stuff and most of the rest is written in Objective C (or Swift).
For these libraries, Apple hosts a function that retrieves the entry points from a different string, called a “selector”.
Here the first string is the alias you will be using for the API call, so no need for an Alias string.
Instead, you must define the selector exactly like you find it in the docs.
So the example Emile mentioned:
Declare Sub centerWindow Lib "AppKit" Selector "center" (windowHandle As Ptr)
means the jump to the address for the method “center” in the framework “AppKit” is being created which needs the handle of the respective window as input parameter. To make it more verbatim, the programmer decided to call it “centerWindow” for the purpose of calling it, but that is only an arbitrary Xojo parameter in this case. He could have simply called it “center” as well.
There is one specialty in addressing ObjC properties by declare:
What you find in Apple’s docs is usually the getter selector of this property. Like
Declare Function bounds lib UIKitLib selector "bounds" (obj_id as Ptr) as CGRect
unless Apple says the getter is named differently, like it is often the case for status properties. Then you will often find a selector like “isActive” instead of “active”
Apple Objective C selectors always start lowercase, or rather use camelcase.
The setter selector, if this property is not read-only, can always be built by camel casing the getter name while adding a “set” to it and finishing it with a colon, which is the ObjC way of separating properties:
Declare Sub setBounds lib UIKitLib selector "setBounds:" (obj_id as Ptr, value as CGRect)
A theoretical animated version of this method taking an animated boolean flag as additional input parameter would therefore look like
Declare Sub setBoundsAnimated lib UIKitLib selector "setBounds:animated:" (obj_id as Ptr, value as CGRect, animated as Boolean)
Hope that helps a bit.
Just as an aside, in the places where Ulrich has UIKitLib in those code examples, those are a constant whose value is “UIKit.framework”. Just the name UIKitLib will not work.
Remove (or comment out) the test method calls (or just the TestCertTools) in App.NewDocument. Something is buggy there.
Yes, removing all the test method the app compiles and you can test different things.
Morever, just for your eyes, in Shared, enable “Support Hi-DPi”.
I’m a happy user.