How can I use dpDisconnect/dpQueryDisconnect from a different script as connecting?
To disconnect a datapoint connections made via dpConnect, dpQueryConnectSingle, dpQeuryConnectAll or dpConnectUserData, the function call of dpDisconnect / dpDisconnectUserData / dpQueryDisconnect needs to be in the same script.
So it is not possible to do a dpConnect in an init script and dpDisconnect via a button click. It is also not possible to do a dpConnect via a button click and execute the dpDisconnect with a click on another button.
A possible solution for that is to use a hidden textfiled that triggers the dpConnect/dpDisconnect on text change:
1) Place a text filed on the panel.
2) Set the text field to invisible.
3) Implement in the text change event the following:
main(){
if(sNewText == “”) //to avoid a recursion
return;
if(sNewText == "1")
dpConnect (….);
else if(sNewText == "0")
dpDisconnect(…)
this.text = “”; //have to reset the text field, otherwise the text change event would not be triggered with the same set text
}
4) The clicked script of the button for dpConnect: textField.text = “1”;
5) The clicked script of the button to dpDisconnect: textField.text = “0”;