C++
ACDBCORE2D_PORT void setWorkingDatabase( AcDbDatabase* pDatabase );
Description
This method may not be overridden.
setWorkingDatabase() may be called by the host application, by database code, and by both dependent and independent ObjectARX applications.
Note that all RealDWG host applications must instantiate and set at least one AcDbDatabase to be the working database. Many areas of ObjectDBX code require a database to query for information. For example, if you make an AcDbEntity in memory, it may require default information from a database. It will take that information from the working database.
If you want to create some form of Multiple Drawing Interface (MDI) application, where your concept of a document includes one or more databases, you'll need to make sure that you update the working database in synch with whatever document switching scheme your application implements.
The working database should never be left set to a database that has been deleted. For example, the following code is likely to cause runtime exceptions:
AcDbDatabase *pDb1 = new AcDbDatabase(kTrue); acdbHostApplicationServices()->setWorkingDatabase(pDb1); delete pDb1; AcDbDatabase *pDb2 = new AcDbDatabase(kFalse); pDb2->readDwgFile("somefile.dwg"); // workingDatabase is still pDb1
The problem is that internally, the call to readDwgFile() is sometimes making use of the workingDatabase() value to make certain decisions. A significant amount of internal AcDb code references the workingDatabase() method. If the working database is a dangling pointer to a deleted database, such code will fail.
Parameters
Parameters | Description |
---|---|
pDatabase | Database to make the new working database |
Notes
If this method is used in an AutoCAD or OEM environment to change the working database to something other then the database displayed in the editor for the currently active document, you may experience unexpected results (including crashing AutoCAD or OEM).