« Back to Frequently Asked Questions

Avoid immediately deleting objects

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Avoid immediately deleting objects
Answer
12/7/18 1:51 PM
Hi!

It sometimes happens to me that I accidentally delete an object when moving too fast through the context menu. The problem is that if the object has some connectors all the connectors are also deleted and I have to model it once again. But if one just cuts the object, then a message is displayed warning that there are some connectors associated with this particular object. This is not the case if one simply selects Delete from the context menu. Is there a possibility to avoid the deleting of the connectors or at least to warn the user before all the objects will be deleted?

RE: Avoid immediately deleting objects
execute on_event external coupling event handler if adoscript add-on implementation delete_objs
Answer
12/10/18 8:13 AM as a reply to Anonymous.
One possibility is to use the "BeforeDeleteInstance" event to execute a script before an instance is deleted. Within the script you can define a query for the user. Thereafter you can use the returned value as an input for the EXIT command to either stop the execution of the code and thus preventing the deletion of an instance or not.

The code for this purpose would look the following (You place the event in the external coupling of your library):
1ON_EVENT "BeforeDeleteInstance" {
2EXECUTE file: ("db:\\EVENT_before_delete_instance.asc") scope:same 
3EXIT(nBeforeDeleteInstanceExit)
4}

In this case the content of the EVENT_before_delete_instance.asc AdoScript file looks the following:
1CC "AdoScript" QUERYBOX "Ary you really sure that you want to delete this object?" yes-no def-no
2# -->RESULT endbutton:strValue
3IF(endbutton = "no") {
4  SET nBeforeDeleteInstanceExit: -1
5} ELSE{
6  SET nBeforeDeleteInstanceExit: 0
7}

Thus,depending on what option the user selects on the querybox the variable “nBeforeDeleteInstanceExit” will hold either -1 or 0. The value serves as a parameter for the EXIT command within the “ON_EVENT” scope. EXIT (0) means that there will be no abortion and the instance will be deleted. EXIT (-1) means that the execution will be aborted without an error and the instance will not be deleted.

See attached an example library with the included event and the corresponding AdoScript file.
Attachments: EVENT_before_delete_instance.asc (0.2k), PreventInstanceDelete.abl (9.5k)