Why would you need different components for loading different dynamic libraries?
Because they are, effectively different Components, think of it as an overload if you like.
When the TTrayIcon is registered, a whole lots initialization is done in the Unity module. And only done once of course. But once it is done, any attempt to create a new TTrayIcon reuses the existing "template" (for lack of a better expression). I don't see any other Component do that.
There is also function SafeLoadLibrary() available. It is used in some places in Lazarus sources.
No, the particular problem is not with loading the library, the Unity module does a good job of loading and seeing if everything it needs is there. The AV shows up much later when TTrayIcon.Show() is called. The AV is happening inside the Ayatana library. I have reported it but no response. I suspect 32bit problems may not have a high priority these days.
Anyway, lets cut to the chase. I have prepared and tested to death
the very simple version my idea, all it does is bring out a Global Var from Unity that the programmer can play with at run time. A couple of changed lines in gtk2wsfactory to make the TrayIcon registration dependent on that Var. It does not make the problem go away but makes it manageable for those who care enough to do so.
I'll post that patch and a tiny demo project later today (to bugs) and will, time permitting spend more trying to understand that issue of how Unity's initialization locks in the Unity TrayIcon. Overall, I think a complete redo of that module is needed, its called "Unity" because it was built to work with that terrible Unity Desktop, I believe Ayatana and KSI have evolved the API a lot since then, maybe there some "hey, I'm working" signals we can get back now ?
David