Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Deleting and Recovering Registered Applications

The registered application table object does not have a method for deleting an application. Each registered application record object deletes itself. When the registered application deletes itself, the database marks it as «erased», and the registered application continues to be stored in the table until the database is not saved in a file. This provides the ability to recover registered applications. Recovery is possible only if the undo process is started for the database, otherwise any objects are deleted permanently. In the following examples, the pRegApps variable stores a pointer to the registered application table object. For example, add an application in the table:


OdDbRegAppTableRecordPtr pRegApp = OdDbRegAppTableRecord::createObject();
pRegApp->setName("AppX");
pRegApps->add(pRegApp);

To start the undo process, use the startUndoRecord() method of the database object. To get the database object from the registered application table object, use its database() method. For example:


pRegApps->database()->startUndoRecord();

Deleting a registered application

To delete a registered application, get the smart pointer to the registered application record object in write mode and use the erase() method when its argument equals True. The erase() method marks the application as «erased» and returns the result status as the OdResult value. For example:


pRegApp = pRegApps->getAt("AppX", OdDb::kForWrite);
OdResult result = pRegApp->erase(true);

The program can use the obtained result value for verification. For example:


if(result) 
  odPrintConsoleString(L"\nError: %d - %s", result, pRegApps->database()->appServices()->getErrorDescription(result).c_str()); 

If the registered application record object is not opened in write mode, the erase() method generates the exception: «62 - Not opened for write».

If the registered application is predefined or is zero, the erase() method generates the exception: "116 - Object can't be erased". Therefore, check the registered application before deleting it. For example:


if(pRegApp->objectId() == pRegApps->database()->getRegAppAcadId())
  odPrintConsoleString(L"\nError: ACAD application can not be deleted");

Recovering a registered application

The registered application marked as «erased» is stored in the database and can be recovered from the table. For recovery, the program must start the undo procedure for the database, otherwise the erase() method deletes the registered application permanently. To recover a registered application, get the smart pointer to the deleted registered application record object in write mode and use the erase() method when its argument equals False. The erase() method marks the registered application as «unerased». For example:


pRegApp = pRegApps->getAt("AppX", OdDb::kForWrite, true);
if(!pRegApp.isNull())
  pRegApp->erase(false);

If the registered application was permanently deleted, the erase(false) method cannot recover it and generates the exception: «104 - Object was permanently deleted».

See Also

Working with Registered Applications

Adding and Naming Registered Applications

Getting and Checking Registered Applications

Example of Working with the Registered Application Table Object

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.