feifff 发表于 2005-11-24 18:44:00

请高手帮忙:同样的命令却有两种结局???

<P>我在无模式对话框编程中想生成一直线报错(\Dlg.cpp(215) : error C2660: 'new' : function does not take 3 parameters)</P>
<P>但是同样的命加入到命令程序中(没有对话框)正常,在家折腾了几天,没有结果,高手能帮帮吗?</P>
<P>下面是我的程序。</P>
<P>void CDlg::xh_creatTab()<BR>{<BR>&nbsp;&nbsp;&nbsp; AcGePoint3d startPt(4.0, 2.0, 0.0);<BR>&nbsp;&nbsp;&nbsp; AcGePoint3d endPt(24.0,2.0,0.0);</P>
<P>&nbsp;&nbsp;&nbsp; AcDbLine *pLine = new AcDbLine(startPt, endPt);&nbsp;</P>
<P>&nbsp;AcDbBlockTable *pBlockTable;<BR>&nbsp;&nbsp;&nbsp; acdbCurDwg()-&gt;getBlockTable(pBlockTable,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDb::kForRead);</P>
<P>&nbsp;&nbsp;&nbsp; AcDbBlockTableRecord *pBlockTableRecord;<BR>&nbsp;&nbsp;&nbsp; pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRecord,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDb::kForWrite);<BR>&nbsp;&nbsp;&nbsp; pBlockTable-&gt;close();</P>
<P>&nbsp;&nbsp;&nbsp; AcDbObjectId lineId;<BR>&nbsp;&nbsp;&nbsp; pBlockTableRecord-&gt;appendAcDbEntity(lineId, pLine);</P>
<P>&nbsp;&nbsp;&nbsp; pBlockTableRecord-&gt;close();<BR>&nbsp;&nbsp;&nbsp; pLine-&gt;close();<BR>}</P>

王咣生 发表于 2005-11-24 18:56:00

reply

把整个工程文件发上来吧,这样容易调试

houdy 发表于 2005-11-24 20:04:00

<P>Modeless dialog is in Application context, that to say, document is not locked and you need explictly lock the document in case you want to open something for write. In the document context, autocad will lock the document for you, that's why the same code can run successfully in command.</P>
<P>PS: You need not locking the document when you just open something for read.</P>
<P>&nbsp;</P>

feifff 发表于 2005-11-24 22:40:00

<P>好的,我将上面一段代码放在void runID()里面,在调用对话框前执行。</P>
<P>我发现这段代码在没有对话框的工程中运行一点问题都没有,但是一旦到含有对话框的工程中(不论是模式还是非模式对话框都一样)就出上上面所讲的问题,谢谢你帮我查查,我就发上来</P>

feifff 发表于 2005-11-24 23:01:00

怎么没传上去啊,出错

houdy 发表于 2005-11-25 20:20:00

<P>Debug the code and check the return value of each function and all the pointer value, from these you can get some clue about the error. </P>

王咣生 发表于 2005-11-25 22:18:00

reply

<P>看看以下内容,是否能有帮助:</P>
<P>默认状态下AutoCAD2004是多文档应用程序,系统变量SDI=0,</P>
<P>acdbHostApplicationServices()-&gt;workingDatabase();</P>
<P>不是指一个文档,而是多个文档.当使用模态对话框时,这个对话框资源属于唯一的一个文档,所以不会产生错误;<BR>而使用非模态对话框时,对话框资源不属于任何一个文档,如果修改往数据库(写操作),就会导致AutoCAD异常.</P>
<P>解决的方法是:</P>
<P>使用非模态对话框时要显式地管理文档的状态,当然,如果不需要多文档,则将系统变量SDI设为1也能解决非模态对话框的问题,<BR>一般以写的方式操作实体时,要将当前文档锁定,操作结束后,解锁文档,而以读的方式打开对象,不需要锁定文档:</P>
<P>acDocManager-&gt;lockDocument(acDocManager-&gt;curDocument(), AcAp::kWrite, NULL, NULL, true);</P>
<P>这个函数的使用是锁定文档以便访问它们的资源,这些资源包括与文档相关联的的数据库对象(AcDbDatabases objects associated with a document),以及这些数据库中的实体对象(AcDbObject objects),还有数据库常驻系统变量(all AcDbDatabase resident system variables).<BR>它还包括了基于系统变量的所有文档(all document based system variables),及与文档关联的事务管理器(the Transaction Manager associated with a document).文档在以AcDb::kForRead打开一个AcDbObject对象时不需要锁定,读取系统变量时也不需要锁定文档.<BR>...<BR>acDocManager-&gt;unlockDocument(acDocManager-&gt;curDocument());</P>
<P><BR>示例:</P>
<P>void lockDocument_Test()<BR>{<BR>&nbsp;AcGePoint3d start(0.0,0.0,0.0), end(10.0,10.0,0.0);<BR>&nbsp;AcDbLine *line = new AcDbLine(start, end);<BR>&nbsp;AcDbBlockTable *pBlockTable;</P>
<P>&nbsp;// 锁定当前文档<BR>&nbsp;acDocManager-&gt;lockDocument(acDocManager-&gt;curDocument(), AcAp::kWrite, NULL, NULL, true);</P>
<P>&nbsp;acDocManager-&gt;curDocument()-&gt;database()-&gt;getBlockTable(pBlockTable, AcDb::kForRead);<BR>&nbsp;//acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable(pBlockTable, AcDb::kForRead);<BR>&nbsp;AcDbBlockTableRecord *pBlockTableRec;<BR>&nbsp;pBlockTable-&gt;getAt(ACDB_MODEL_SPACE, pBlockTableRec, AcDb::kForWrite);<BR>&nbsp;pBlockTable-&gt;close();<BR>&nbsp;AcDbObjectId objId;<BR>&nbsp;pBlockTableRec-&gt;appendAcDbEntity(objId, line);<BR>&nbsp;line-&gt;close();<BR>&nbsp;pBlockTableRec-&gt;close();<BR>&nbsp;// 运行完解锁文档<BR>&nbsp;acDocManager-&gt;unlockDocument(acDocManager-&gt;curDocument());<BR>}</P>

feifff 发表于 2005-11-27 00:21:00

<P>谢谢王咣生版主回答,但是我用的是AutoCADR14版本(因为单位用的是R14版本的)。</P>
<P>我测试了一下,只要我用MFC AppWizard生成工程,就出这方面的问题(不论是模式对话框不是非模式对话框),我估计应该是MFC中有什么函数与它发生冲突,但又不象(真想不明白MFC会重载这个函数),这个问题只有象你这类高手才能解决,我很菜,不知ARX怎样调试,看论谈,好象是先设断点,再按F5等就进入CAD内进行调试,但这个工程无法编译</P>

kswzc 发表于 2005-12-28 20:42:00

<P>你还应该加一个让cad获得焦点的函数</P>

ishou 发表于 2005-12-28 21:13:00

<P>大概是 MFC在 CDlg 中重定义 new,&nbsp; 好在编译没有通过,如果通过,重定义的 new 与 ACAD中要求的 new 可能不一致,可能会引起内存泄漏!</P>
<P>你可以在 CDlg外 new 一个 AcDbLine:</P>
<P>AcDbLine *MyNewLine(AcGePoint3d&nbsp; startPt,&nbsp; AcGePoint3d endPt)</P>
<P>{</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp; new AcDbLine(startPt, endPt);</P>
<P>}</P>
<P>void CDlg::xh_creatTab()<BR>{<BR>&nbsp;&nbsp;&nbsp; AcGePoint3d startPt(4.0, 2.0, 0.0);<BR>&nbsp;&nbsp;&nbsp; AcGePoint3d endPt(24.0,2.0,0.0);</P>
<P>&nbsp;&nbsp;&nbsp;///////////////////// AcDbLine *pLine = new AcDbLine(startPt, endPt);</P>
<P>&nbsp; AcDbLine *pLine = MyNewLine(startPt, endPt);&nbsp;&nbsp; // &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;</P>
<P>&nbsp;</P>
<P>&nbsp;AcDbBlockTable *pBlockTable;<BR>&nbsp;&nbsp;&nbsp; acdbCurDwg()-&gt;getBlockTable(pBlockTable,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDb::kForRead);</P>
<P>......................................</P>
<P>&nbsp;</P>
页: [1]
查看完整版本: 请高手帮忙:同样的命令却有两种结局???