Page 1 of 1

Ultralabel disposed object

PostPosted: Tue Nov 27, 2018 12:40 pm
by Riyaz
Hi There

Am currently working on a plugin which adds a dropdown to the PO panel, all works fine the first time, but if you close and reopen the purchase order, it comes with the below exception,

Error: "Cannot access a disposed object"
Object Name: 'Ultralabel''
Module: 'CreateHandle'

Have attached the plugin, can you pls kindly advise

Re: Ultralabel disposed object  Topic is solved

PostPosted: Tue Nov 27, 2018 12:59 pm
by Mike.Sheen
This is caused by creating new controls and storing them as fields in the FormPlugin class.

The class is instantiated ONCE at login time, then the methods SetupBeforeHandlers and Setup are invoked when a form loads IF that form was added to the Forms tab of the plugin.

When creating controls and adding them to a form, they'll be destroyed when the form closes - but your fields in the FormPlugin still reference them.

The easiest way around this is to not have these controls as fields - create them in the Setup method and store them in the GenericObjectCollection of the form. When you want to access them, retrieve them from the GenericObjectCollection.

Your plugin modified to do this is attached.