递归火山软件开发平台

标题: 研究了下虚函数子类重写都失败了如何解决 [打印本页]

作者: 沉默流星    时间: 前天 20:33
标题: 研究了下虚函数子类重写都失败了如何解决
在封装时遇到1.子类重写父类虚函数,并且子类当中还调用一个宏用来跟父类绑定

原生代码如下:
(, 下载次数: 8)

(, 下载次数: 10)


方式1 使用@接口 (失败)
因:接口实现的是子类调用。但无法让子类实现的这个函数体内写内容
(, 下载次数: 8)


方式2 通过@视窗后缀文本 整成事件则报错
(, 下载次数: 8)


要实现这种,应该怎么做。
1.@虚拟方法 可覆盖
如果使用虚拟方法 应该怎么实现
2.@视窗.后缀文本
如果使用这个 如何处理这个报错问题
3.使用变量
如果使用变量实现,应该如何实现


为了方便预览,源代码贴在2楼.

作者: 沉默流星    时间: 前天 20:35

  1. // 自定义对象.h
复制代码
  1. //自定义对象.cpp
  2. #include "stdafx.h"
  3. #include "自定义对象.h"
  4. #define VERSION_ZFFDWGSCALE 1

  5. ACRX_DXF_DEFINE_MEMBERS(自定义对象, AcDbObject,
  6.         AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
  7.         AcDbProxyObject::kNoOperation,
  8.         ZFFDWGSCALE, ZffCustomObjectDB);

  9. 自定义对象::自定义对象()
  10. {
  11.         //{{AFX_ARX_DATA_INIT(ZffDwgScale)
  12.         //}}AFX_ARX_DATA_INIT

  13.         m_infoScale = 0;
  14.         m_lableScale = 0;
  15. }

  16. 自定义对象::~自定义对象()
  17. {
  18.         // TODO: clean up.

  19. }


  20. Acad::ErrorStatus 自定义对象::dwgInFields(AcDbDwgFiler* pFiler)
  21. {
  22.         assertWriteEnabled();
  23.         Acad::ErrorStatus es;

  24.         // Call dwgInFields from AcDbObject
  25.         if ((es = AcDbObject::dwgInFields(pFiler)) != Acad::eOk) {
  26.                 return es;
  27.         }

  28.         // Read version number.
  29.         Adesk::UInt16 version;
  30.         pFiler->readItem(&version);
  31.         if (version > VERSION_ZFFDWGSCALE)
  32.                 return Acad::eMakeMeProxy;

  33.         // Read the data members.
  34.         switch (version)
  35.         {
  36.         case (1):
  37.                 // TODO: here you can file datamembers not
  38.                 //       created by the ObjectARX Add-In.
  39.                 pFiler->readItem(&m_infoScale);
  40.                 pFiler->readItem(&m_lableScale);

  41.                 break;
  42.         }


  43.         return pFiler->filerStatus();
  44. }

  45. Acad::ErrorStatus 自定义对象::dwgOutFields(AcDbDwgFiler* pFiler) const
  46. {
  47.         assertReadEnabled();
  48.         Acad::ErrorStatus es;

  49.         // Call dwgOutFields from AcDbObject
  50.         if ((es = AcDbObject::dwgOutFields(pFiler)) != Acad::eOk) {
  51.                 return es;
  52.         }

  53.         // Write version number.
  54.         pFiler->writeItem((Adesk::UInt16)VERSION_ZFFDWGSCALE);

  55.         // Write the data members.
  56.         // TODO: here you can file datamembers not
  57.         //       created by the ObjectARX Add-In.
  58.         pFiler->writeItem(m_infoScale);
  59.         pFiler->writeItem(m_lableScale);

  60.         return pFiler->filerStatus();
  61. }

  62. Acad::ErrorStatus 自定义对象::dxfInFields(AcDbDxfFiler* pFiler)
  63. {
  64.         assertWriteEnabled();
  65.         struct resbuf rb;

  66.         if ((AcDbObject::dxfInFields(pFiler) != Acad::eOk) ||
  67.                 !pFiler->atSubclassData(L"ZffDwgScale"))
  68.                 return pFiler->filerStatus();

  69.         // Read version number.
  70.         pFiler->readItem(&rb);
  71.         if (rb.restype != AcDb::kDxfInt16) {
  72.                 pFiler->pushBackItem();
  73.                 pFiler->setError(Acad::eInvalidDxfCode,
  74.                         L"nError: expected object version group code %d",
  75.                         AcDb::kDxfInt16);
  76.                 return pFiler->filerStatus();
  77.         }
  78.         else {
  79.                 Adesk::UInt16 version = rb.resval.rint;
  80.                 if (version > VERSION_ZFFDWGSCALE)
  81.                         return Acad::eMakeMeProxy;
  82.         }

  83.         // 读取条件图比例
  84.         pFiler->readItem(&rb);
  85.         if (rb.restype != AcDb::kDxfInt32)
  86.         {
  87.                 pFiler->pushBackItem();
  88.                 pFiler->setError(Acad::eInvalidDxfCode,
  89.                         L"nError: expected object version group code %d",
  90.                         AcDb::kDxfInt32);
  91.                 return pFiler->filerStatus();
  92.         }
  93.         else
  94.         {
  95.                 m_infoScale = rb.resval.rlong;
  96.         }

  97.         // 读取出图比例
  98.         pFiler->readItem(&rb);
  99.         if (rb.restype != AcDb::kDxfInt32)
  100.         {
  101.                 pFiler->pushBackItem();
  102.                 pFiler->setError(Acad::eInvalidDxfCode,
  103.                         L"nError: expected object version group code %d",
  104.                         AcDb::kDxfInt32);
  105.                 return pFiler->filerStatus();
  106.         }
  107.         else
  108.         {
  109.                 m_lableScale = rb.resval.rlong;
  110.         }

  111.         return pFiler->filerStatus();
  112. }

  113. Acad::ErrorStatus 自定义对象::dxfOutFields(AcDbDxfFiler* pFiler) const
  114. {
  115.         assertReadEnabled();
  116.         Acad::ErrorStatus es;

  117.         if ((es = AcDbObject::dxfOutFields(pFiler)) != Acad::eOk)
  118.                 return es;

  119.         // Write subclass marker.
  120.         pFiler->writeItem(AcDb::kDxfSubclass, "ZffDwgScale");

  121.         // Write version number.
  122.         pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16)VERSION_ZFFDWGSCALE);

  123.         // 写入两个成员变量
  124.         pFiler->writeItem(AcDb::kDxfInt32, m_infoScale);
  125.         pFiler->writeItem(AcDb::kDxfInt32, m_lableScale);

  126.         return es;
  127. }

  128. void 自定义对象::Set(int infoScale, int lableScale)
  129. {
  130.         assertWriteEnabled();

  131.         m_infoScale = infoScale;
  132.         m_lableScale = lableScale;
  133. }

  134. int 自定义对象::GetInfoScale() const
  135. {
  136.         assertReadEnabled();

  137.         return m_infoScale;
  138. }

  139. int 自定义对象::GetLabelScale() const
  140. {
  141.         AcDbObject* dx;
  142.         dx->dxfOutFields(a);
  143.         assertReadEnabled();

  144.         return m_lableScale;
  145. }


复制代码



作者: niuyanbo2021    时间: 昨天 07:17
顶贴,望大佬助力,谢谢!




欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/) Powered by Discuz! X3.4