Sender anomaly

agraham

Expert
Licensed User
Longtime User
The construct "Sender.SomeProperty" seems to always work in the IDe with both library and intrinsic objects. However when optimised compiled it usually fails on library objects with an invalid cast exception as the compiler tries to cast it a specific type, like Control, or interface, like IText, which it does not necessarily inherit.

I don't know if the behaviour in the IDE is intended or a side effect but some clarification on the intended use of Sender and SenderFullName would be welcome.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Generally speaking you should always use SenderFullName instead of Sender and use it as a parameter of Control:
B4X:
Control(SenderFullName, Button).color = cred
Sender returns the control (or object) name without the module and therefore will fail when the control resides in a different module.
This case is the same as the Control keyword case.
As we tried to avoid breaking existing code Sender and SenderFullName can also be used with the former syntax: Sender.SomeProperty.
This will only work with internal controls and with the properties listed on this page: Basic4ppc - Main Help
 
Top