dpQueryDisconnect()

Ends registration to a work function of dpQuerysConnectAll() or dpQueryConnectSingle()

Synopsis

int dpQueryDisconnect([class object,] string|function_ptr work, anytype userData);

Parameters

Parameter Meaning
object An object of a Control++ class.
work

Name of the callback function ("work function") that is called when data point values change.

Or

The name of a function pointer to the work function (callback function).

userData User-defined data which is passed as parameter to the callback function.

Return Value

dpQueryDisconnect() returns 0 , -1 in the event of an error.

The return value only indicates whether a CONNECT message was sent, but not whether the execution of the function (query) was successful. The error is written to the thread after the function has been executed and can be retrieved with a subsequent call to the function getLastError(). See also Error Handling.

Error

Errors can be retrieved with getLastError(). This includes missing arguments (also of the work function), undefined functions, incorrect arguments ( for example, no Control expression) , and if no identifier or query is specified. The usage of not initialized variables for the parameter userData will raise an error.

Description

The function dpQueryDisconnect() ends the registration to a work function which was called via the function dpQueryConnectAll(). The connection to the work function "examplFunc" in the first parameter "wf" (of the dpQueryDisconnect function) is cancelled.

Note: The dpQueryDisconnect() function must always be called via the same script as the dpQueryConnectAll() function!
main()
{
  string wf = "examplFunc";              //Definition of the callback function "examplFunc"
  anytype userData = getUserName();      //The current user name is passed as user
  dyn_dyn_anytype tab;                   //Definition of the parameters for the function 
                                         //dpQueryConnectAll, dpQueryDisconnect and callback function "examplFunc"
  int queryAll, blockTime, dpQuery;
  string query;
  bool ans = TRUE;                       //The callback function is called directly after registration
  blockTime = 0;                         //No blocking time (delay)

  //Definition of the SQL query:
  query = "SELECT '_online.._value' FROM '*' WHERE _LEAF AND '_online.._userbit7' == 1";
  //Registration to the function:
  queryAll = dpQueryConnectAll(wf, ans, userData , query, blockTime);

  DebugN("Registration successful?? ", queryAll);   //0 = successful

  //Registration to the callback function:
  dpQuery = dpQueryDisconnect(wf, userData);
  DebugN("Registration successful? ", dpQuery);     //0 = successful
}

//Callback function 
void examplFunc(anytype userData, dyn_dyn_anytype tab)
{
  int z, length;
  length = dynlen(tab);

  DebugN("Length: ", length, "User: ", userData);   //Go through result table (result of the SQL query)
  
  for(z=1;z<=length;z++)
  {
    DebugN(tab[z]);
  }
}              

You can find an example of how to use a Control++ class instance in a connect function in the chapter dpConnect().

Assignment

Data point function, waiting Control function

Availability

CTRL