I recently came across a very weird behavior when trying to override callbacks in derived classes in CTRL++.
please consider the following simple example
(for reasons of space I put everything together)
Dpl for Import
Code: Select all
# ascii dump of database
# DpType
TypeName
TestPump.TestPump 1#1
State 25#2
Value 21#3
# Datapoint/DpId
DpName TypeName ID
Pump1 TestPump 18246
Code: Select all
class BaseLogic
{
public BaseLogic()
{
//default constructor
}
public void init()
{
setupConnect();
}
protected void setupConnect()
{
dpConnect(this, this.cbOnPumpStateChanged, true, "Pump1.State");
dpConnect(this, this.cbOnPumpValueChanged, true, "Pump1.Value");
}
// can be overridden
protected void cbOnPumpStateChanged(string sDpPumpState, string sState)
{
DebugTN(__FUNCTION__,sDpPumpState,sState);
}
//must not be overriden
private void cbOnPumpValueChanged(string sDpPumpValue, int iValue)
{
DebugTN("Private Callback");
DebugTN(__FUNCTION__,sDpPumpValue,iValue);
}
};
class ExtendedLogic : BaseLogic
{
public ExtendedLogic()
{
//Default constructor
}
//@Override:
protected void cbOnPumpStateChanged(string sDpPumpState, string sState)
{
DebugTN("Overridden method for callback");
DebugTN(__FUNCTION__,sDpPumpState,sState);
}
};
public void main()
{
ExtendedLogic logic;
logic.init();
dpConnect("cbTest", false, "Pump1.State"); //just to prevent the ctrl manager from exiting
}
public void cbTest(string dp, string state)
{
}
When trying to run this, you will get a very weird exception:
Code: Select all
SEVERE, 73, Variable not defined, Line: 14, this.cbOnPumpStateChangedExpected behavior:
It should be possible to use a protected method in a derived class for overriding a callback from a super class
I would consider this as a bug, please let me know if you agree or if the behavior is intended.
Thanks!