>> BlockTableRecord blkTblRec = new BlockTableRecord();
Why are you creating a new instance of a BlockTableRecord,
if you're not adding a new block definition to the drawing?
That's what's causing the runtime to complain. You're creating
a new BlockTableRecord, but you don't use it.
Right after that, the variable you assigned that new instance
to is subsequently reassigned to another instance of that
same class (returned by GetObject()).
DisposableWrapper sees that your code has problems and so
it lets you know about that.
If that's exactly what appears in the Autodesk sample code,
it's quite possible that it predates the AutoCAD 2006 API,
where there were significant differences in how you handled
opening/closing of objects.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
"perry"
wrote in message news:5255514@discussion.autodesk.com...
In the partial code listing below is a line which I call many times, and Im sure most other programmers
do as well. It comes straight out of the Adesk docs (trans.getobject...).
Problem is everytime I use it the debugger IDE tells me I "forgot" to close the record, even though
you can see that I do. Funny thing is I dont get a similar "warning" about closing the block table
which uses the same mechanism.
Is this an Acad net wrapper bug?
-----------------------------------------------------------------------------------------------
private void checkBlockDef()
{
int attCount = 0;
using (Database dBase = HostApplicationServices.WorkingDatabase)
{
Transaction trans = dBase.TransactionManager.StartTransaction(); // begin the transaction
try
{
//Now, drill into the database and obtain a reference to the BlockTable
BlockTable blkTbl = (BlockTable)trans.GetObject(dBase.BlockTableId, OpenMode.ForWrite);
BlockTableRecord blkTblRec = new BlockTableRecord();
if (blkTbl.Has("TBREVISION"))
{
//check number of attribute definitions
//See notes 1
// either of the next two lines will give the following warning in the debugger on exit
//Forgot to call Dispose? (Autodesk.AutoCAD.DatabaseServices.BlockTableRecord): DisposableWrapper
// blkTblRec = (BlockTableRecord)trans.GetObject(Utilities.getRevDef(dBase, trans), OpenMode.ForRead, false);
blkTblRec = (BlockTableRecord)trans.GetObject(blkTbl["TBREVISION"], OpenMode.ForRead, false);
}
trans.Commit(); //All done, no errors? Go ahead and commit!
blkTblRec.Dispose();
blkTbl.Dispose();
}
catch (System.Exception ex)
{
Utilities.Message(ex);
}
finally
{
trans.Dispose();
}
}//end using database
}