Reset ADS-OCX application
After a program error, it is often not possible to terminate the application via the operating function "Start -> Program Reset", as is usually the case. The following message of the debugger is the consequence:

The cause of this is that using the ADS-OCX generates a client-server connection to the TwinCAT router, and this must be closed when the application stops. The Delphi application cannot be closed using the "Program Reset" menu command, because at this point there is a connection to the TwinCAT router. Their connection is generated in the application through the assignment of the AdsAmsNetId and the port number.
The following methods may be used to close the application without having to restart the computer:
- First confirm the runtime error with OK, then stop the TwinCAT system via the taskbar, and then reset the Delphi application. This causes existing connections to the clients to be closed. The disadvantage is that the TwinCAT system and the PLC must then be restarted;
- First confirm the runtime error with OK, then call the Router Cleanup via the taskbar, and then reset the Delphi application;
- Make use of exception handling. The AdsAmsDisconnect() can be used to explicitly close the connection to the router;
- try n:=8; Switch[n].Tag:=0; // This index is invalid except on EAccessViolation do begin AdsOcxSPS.AdsAmsDisconnect(); Application.Terminate(); end; end;