# CallDelegateOnMainThreadMBS Can't Handle Nil Variants

**URL:** <https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539>\
**Category:** Extras\
**Created:** [July 5, 2026, 3:44pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539 "2026-07-05T15:44:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 3:44pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/1 "2026-07-05T15:44:33Z")

</div>

@Christian_Schmitz

The MBS documentation for CallDelegateOnMainThreadMBS says

_“Our plugin supports various combinations of up to 2 parameters of type string, variant, boolean, double, integer and object.”_

Nil is a valid value for a Variant, but passing a Nil Variant parameter via CallDelegateOnMainThreadMBS throws a NilObjectException, so it doesn’t really fully support Variant.

I have this code which works when Details is Nil:

`EventHandler(HandlerObj.Value).HandleNotification(EventType, Details) //EventHandler is an Interface, EventType is a String, and Details is a Variant`

and I want to make it thread-safe using the MBS method. This, however, throws an NOE when Details is Nil:

`CallDelegateOnMainThreadMBS AddressOf EventHandler(HandlerObj.Value).HandleNotification, EventType, Details`

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [July 5, 2026, 6:11pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/3 "2026-07-05T18:11:55Z")

</div>

If you get a NilObjectException, please check the message.

Our plugin would state if the delegate object or function is nil.

The parameter should not cause such an error.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 6:25pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/4 "2026-07-05T18:25:06Z")

</div>

NOE message info never shows anything

 ![image](https://forum.xojo.com/uploads/default/original/3X/d/e/de834c2a62da571456acaf4a4a0828a1c74ce7bd.jpeg)

The only thing that’s Nil is Details

 ![image](https://forum.xojo.com/uploads/default/original/3X/a/f/af9caba2ae0a11b894bc285d45779aac822eeff9.png)

The WeakRef HandlerObj contains a reference to App. App conforms to the Interface and has a method

`HandleNotification(EventName As String, Details as Variant)`

I tried it with the deprecated CallMethodOnMainThreadMBS and that doesn’t throw an NOE but it returns False, indicating failure.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 6:27pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/5 "2026-07-05T18:27:24Z")

</div>

Ah, you’re right - if I assign a non-nil value to Details it still throws an NOE. So it seems maybe something to do with the the delegate resulting from AddressOf.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 6:51pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/6 "2026-07-05T18:51:00Z")

</div>

If I do

`CallDelegateOnMainThreadMBS AddressOf App.HandleNotification, EventType, Details`

it runs without error, but the problem is that the HandleNotification method can be on any object that conforms to the interface, not just App - that’s the point of using an interface.

So this works

`EventHandlerIJ(HandlerObj.Value).HandleNotification(EventType, Details)`

because it calls the interface method directly, but with

`CallDelegateOnMainThreadMBS AddressOf EventHandler(HandlerObj.Value).HandleNotification, EventType, Details`

**AddressOf** doesn’t work with the interface method, and I don’t know why.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 7:12pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/7 "2026-07-05T19:12:40Z")

</div>

AI explanation:

_“`AddressOf` resolves at compile time against the static type, and when you wrap the object in an interface cast, the runtime delegate comes back Nil because Xojo can’t bind through the interface vtable that way.”_

So it seems I need some kind of “interface forwarding” scheme.

Sorry for casting (no pun intended) aspersions on the plugin, @Christian_Schmitz. I’d change the topic title if I could.

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [July 5, 2026, 7:23pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/8 "2026-07-05T19:23:17Z")

</div>

What if you do something like

```xojo
theEventHandler = EventHandler(HandlerObj.value)

CallDelegateOnMainThreadMBS AddressOf EventHandler(HandlerObj.Value).HandleNotification, EventType, Details

```

That might cause it to resolve properly.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [July 5, 2026, 8:34pm UTC](https://forum.xojo.com/t/calldelegateonmainthreadmbs-cant-handle-nil-variants/88539/9 "2026-07-05T20:34:15Z")

</div>

Claude sorted it for me. Instead of storing interface objects and directly calling methods on them, “Forwarder” objects are instantiated and stored for each target object. Each Forwarder has a WeakRef to the target and its own method with the required signature, which in turn calls the interface method on the target:

```auto
Public Sub HandleNotification(EventType As String, Details As Variant)
  If Target <> Nil And Target.Value <> Nil Then
    EventHandlerIJ(Target.Value).HandleNotification(EventType, Details)
  End
End Sub

```

AddressOf can now be called on the HandleNotification method of the Forwarder object, so it works with the MBS method:

```auto
Dim fwd As NotificationForwarder = HandlersArray(HandlerIndex)

If fwd.Target.Value <> Nil Then
  CallDelegateOnMainThreadMBS AddressOf fwd.HandleNotification, EventType, Details
End If

```
