Quick Question: Does anyone know where there is a good tutorial for using “Declare” as I am trying to learn how to do this. I saw one from Javier but when I followed the steps in it, it would not work.
I am assuming it is me, not Javier.
So if anyone knows where I can find a good one, it would be appreciated.
Bad example; why ? The original API call from the macOS documentation is not provided. The reader have to think to search for it to compare how macOS API call are translated to Xojo.
I checked the automatic translation and it is somewhat understandable. So while this is old, it gives at least an introduction to method declares. And links more information at the bottom.
Maybe you should read all the text then.
A link to the API call is provided, and when you open it in another tab you are not even guided on how to note the framework it belongs too but also get an idea of how Apple’s docs are built.
Right, but my point is that you need to understand some things about Objective-C and C before you get into declares because that’s what declares are under the hood.
But like I said, the code assistants in my library are there to help you with them. It’s mostly as simple as finding the call you want to make in Apple’s docs, copying the call and then telling Xojo to convert into a declare. You’ll still need to look at the docs and understand the parameter types for methods and return types to decide if any of the parameters are integers or enums where the script can’t work it out.
I’m no expert, but have used them some in the past. A declare is just a call into a subroutine or function that exists in the operating system. The parameters and return value(s) have a strictly-defined format and strictly-defined types that you must adhere to. That format is provided by the operating system’s API. Return values are very often passed “ByRef”, i.e. as pointers, i.e. you have to provide the variable in which the return value will be passed.
You can define your Declares in Xojo either with the Declare statement:
Soft Declare Function EApiGPIOGetDirection Lib "aaeonEAPI.dll" (Pnum As UInt32, BitMask As UInt32, ByRef Dir As Uint32) As UInt32
or by adding it to External Methods in the Navigator: