Declare tutorial

Hi All.

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.

Regards

Your code or Javier code ?

you could try to ask chatgpt or claude for help in these domain, they are really helpful, even on xojo code and also on declares.

Read the docs:

How do I contact Claude, please.

My code.

I found a blog post by Javier but I couldn’t get it to work.

Hi Martin.

I have gone through the documentation, however there are … concepts that I am not grasping.

Regards

https://claude.ai/login

@Michael_Cebasek
It would be helpful to know which platform you are targeting.

For instance have a script for the IDE that helps with macOS declares:

There are some helpful ebooks around, like “I with I knew how to … windows declares”

https://forum.xojo.com/t/windows-declare-book-updated-to-4-7-sept-2024/81824

Keep in mind that you also need to have an understanding of the underlying APIs to be successful.

1 Like

@Eugene_Dakin has written a book on Windows Declares

not sure if he has one for Mac.

1 Like

I don’t have one for Mac, and am working on one for the Raspberry Pi.

1 Like

Hi Greg.

I’m self taught to programming, so when I look at the documentation about Declares it goes right over my head.

It is like me trying to hold the wind.

So I need somewhere to start with the basics.

Thank you for the response.

Regards

Hi Eugene.

I’m working on a Mac.

Regards

I only read the Declare Sub centerWindow.

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.

Do you know about macOSLib ?

Lots of Declare there…

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.

1 Like

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.

1 Like

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:

Once it’s defined, you call it like any other function in Xojo:

Dim Dir As UInt32
Dim ReturnCode As UInt32 = GetPinDirection(PinNum-1,BitMask, Dir)
HandleReturnCode(ReturnCode)

That’s the basics :slight_smile:

1 Like

No, there is not for the function example I gave.

Yes, you are right, below there is the original API (I think it is), but for a different API.

Regards