Referencing External Libraries

Hello:

I have a few external classes (written in Xojo) that I would like to combine into a single library such that I can somehow reference that library in different Xojo desktop applications.

I am thinking in terms of how the Declare statement works for referencing and using Windows APIs. This way, the library (or libraries if they cannot be combined into one) can be placed in a shared folder and referenced by the different programs I’m writing.

Is it possible in Xojo to dynamically load (via code) the library binary and then instantiate the objects that way?

There’s no way to do what you’re describing in Xojo today.

That said, you can use external items.

  1. Create a project that has your library items in it.
  2. Right-click on an item and select “Make External”. If you’re saving in text format, the format of this item should be XML.
  3. In another project, you can drag the library to the navigator while holding down a key combo
    1. CMD-OPT on macOS
    2. CTRL-OPT on Windows (?)
  4. Save the project

This should leave the project in a state where it always references that file.

One item to note:

External item’s don’t auto-update in open projects. That is, if you have two projects open that reference the same external item and make a change in one of them, the change will not be reflected in the other. If you change the other project and save, the changes from the first project may be overwritten.

4 Likes

Using External Items is not ideal, but it works (keeping in mind @Greg_O’s comments).

It’s better than the alternative of Git and submodules. I know, I’ve tried.

Next up on the Xojo Roadmap - Xojo LibrariesPortions of protected Xojo code that are easily shared between projects and developers.:crossed_fingers:

Libraries should (hopefully) replace the need for External items.

1 Like

I’ll give that a try.

It would be a great addition. The developer could update the shared library and post the compiled binary on that shared folder and all of the apps that reference it would have those big fixes or additional functionality.

Thanks.

That is not true in 2021r2.1, maybe it’s changed since then. I use a lot of externals and usually have a bunch of apps open, as they’re all part of the same ecosystem. Change something in any external and it’s instantly changed in all open apps.

What does happen is that once an external item is edited in an app, that app becomes the “owner” of that external and the external is not editable in any other open app. Closing and reopening any app restores editability in the newly-reopened app.

4 Likes