Let n_pbni denote a non-visual object exported by a PBNI-Extension and let n_derived denote a class that was inherited from n_pbni. Assume that n_derived's constructor and destructor are implemented and reference global variables that are part of the corresponding application object.
In constrast to pure powerscript hierarchies the statement CREATE n_derived would solely call PBX_CreateNonVisualObject and neglegt the constructor of n_derived.
As mentioned here the implementation of n_derived's base class n_pbni has to assure that the constructor of n_derived is called too. Therefore during the call to PBX_CreateNonVisualObject the pbobject instance passed to it is used retrieve its specific class type and when this differs from the native class type to trigger it's constuctor event. This way n_derived is instantiated correctly when the statement CREATE n_derived is evaluated.
The surprise comes when trying to open the script of n_derived in a painter:
On a side note, everytime a PBNI object is opened with the user object painter an instance of the PBNI-object is created. This also applies for objects inheriting a PBNI-object:
- Clicking on n_derived will open the painter.
- The painter calls PBX_CreateNonVisualObject for n_pbni with a pbobject instance of type n_derived
- n_pbni triggers the constructor of n_derived
- the constructor of n_derived fails with an exception since the global variable of the application object was not instantiated.
- The painter is closed before it was even showing.
When replacing the base of n_derived with a non-PBNI base class the painter just opens without triggering any constructor/destructor events.
So in order to mimic the same behaviour for PBNI based objects and their descendands triggering the constructor/destructor events needs to be ommitted when PBX_CreateNonVisualObject is called from the IDE's painter.
Is there a way to reliably determine that a PBNI object is being instantiated from within the IDE's painter?
Thanks in advance
Rudolf Alexander Kerbitz