[Bug?] [3.17] Very Strange Behavior with Overriding Protected Callbacks in derived Classes

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
moto3101
Posts:37
Joined: Tue Aug 22, 2017 2:04 pm

[Bug?] [3.17] Very Strange Behavior with Overriding Protected Callbacks in derived Classes

Post by moto3101 »

Hello together,

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 Example for CTRL manager

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.cbOnPumpStateChanged
However, when you change the visibility of the overriding method in ExtendedLogic to public (public void cbOnPumpStateChanged), it works.

Expected 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!
Last edited by moto3101 on Wed Mar 17, 2021 5:40 pm, edited 1 time in total.

moto3101
Posts:37
Joined: Tue Aug 22, 2017 2:04 pm

Re: [Bug?] [3.17] Very Strange Behavior with Overriding Callbacks in derived Classes

Post by moto3101 »

There also seems to be a problem with the "this" operator for protected methods:

Executing this

Code: Select all

class BaseLogic
{

  public BaseLogic()
  {
    //default constructor
  }
  public void init()
  {
    this.setupConnect();
  }
  protected void setupConnect()
  {
    DebugTN("baseClass SetupConnect!");

  }
  


};

class ExtendedLogic : BaseLogic
{

  public ExtendedLogic()
  {
    //Default constructor
  }
  protected void setupConnect()
  {
    DebugTN("derived class SetupConnect!");
  }

  

};

public void main()
{
  ExtendedLogic logic;
  logic.init();
}
Results in an error:

Code: Select all

SEVERE,     73, Variable not defined,    Line: 10, this.setupConnect()
When just calling setupConnect(); (and deleting the "this.") it works

moto3101
Posts:37
Joined: Tue Aug 22, 2017 2:04 pm

Re: [Bug?] [3.17] Very Strange Behavior with Overriding Protected Callbacks in derived Classes

Post by moto3101 »

Should I additionally report this as a bug?

3 posts • Page 1 of 1