FPC has the infrastructure to do this. See: fpcsrc/fpc-3.2.2/packages/univint/src/DictionaryServices.pas
No, I've not used it myself and so have no working examples. You will be the pioneer here
That's great, thanks! Challenge accepted
One more question if I may:
In the unit DictionaryServices.pas I read:
The result range can be used as an input parameter of DCSCopyTextDefinition() and HIDictionaryWindowShow() in Carbon framework.
Now, HIDictionaryWindowShow() is what I want to do -- trigger the opening of a window with the definition in it, managed by macOS. But above it says that this can only be done with Carbon (i.e. not Cocoa, which is what we need nowadays). And indeed HIDictionaryWindowShow is not implemented in the above unit.
Note that the current Apple documentation says:
An alternative to getting the definition returned to you is to let Dictionary Services obtain and display the search results for you. In this case, instead of calling DCSCopyTextDefinition, you would pass the text range to the HIDictionaryWindowShow function.
So is seems that the "WindowShow" functionality is available in Cocoa.
I think I will try to implement it anyway, by copying the way things are done with the other methods that are already implemented in DictionaryServices.pas, and see if I manage to make it work.
But if anyone has a better understanding of the matter, then any suggestion or explanation in this regard will be greatly appreciated and probably same me from going down a lot of rabbit holes that lead to nowhere...
Thanks again!
[Edited to fix tags.]