对CMFCPropertyGridProperty SetValue时容易报错,这种情况一般是Property和value的类型不匹配造成的。

在创建property的时候,指定了数据类型,如果setvalue时的数据类型与创建时的不一致便会报错。

CMFCPropertyGridProperty的数据类型为_variant_t,它是一个包含了各种数据类型的集合,MSDN中的描述如下:_variant_t对象封装了VARIANT数据类型。 该类管理资源分配和释放,并根据需要对VariantInit和VariantClear进行函数调用。MSDN链接

所以我们在创建property的时候一定要用_variant_t构造函数确定property的数据类型。构造函数的MSDN链接

Remarks

 
  • _variant_t( )   Constructs an empty _variant_t object, VT_EMPTY.

  • _variant_t( VARIANT& varSrc )   Constructs a _variant_t object from a copy of the VARIANT object. The variant type is retained.

  • _variant_t( VARIANT* pVarSrc )   Constructs a _variant_t object from a copy of the VARIANT object. The variant type is retained.

  • _variant_t( _variant_t& var_t_Src )   Constructs a _variant_t object from another _variant_t object. The variant type is retained.

  • _variant_t( VARIANT& varSrc, bool fCopy )   Constructs a _variant_t object from an existing VARIANT object. If fCopy is false, theVARIANT object is attached to the new object without making a copy.

  • _variant_t( short sSrc, VARTYPE vtSrc = VT_I2 )   Constructs a _variant_t object of type VT_I2 or VT_BOOL from a short integer value. Any other VARTYPE results in an E_INVALIDARG error.

  • _variant_t( long lSrc, VARTYPE vtSrc = VT_I4 )   Constructs a _variant_t object of type VT_I4VT_BOOL, or VT_ERROR from a long integer value. Any other VARTYPE results in an E_INVALIDARG error.

  • _variant_t( float fltSrc )   Constructs a _variant_t object of type VT_R4 from a float numerical value.

  • _variant_t( double dblSrc, VARTYPE vtSrc = VT_R8 )   Constructs a _variant_t object of type VT_R8 or VT_DATE from a double numerical value. Any other VARTYPE results in an E_INVALIDARG error.

  • _variant_t( CY& cySrc )   Constructs a _variant_t object of type VT_CY from a CY object.

  • _variant_t( _bstr_t& bstrSrc )   Constructs a _variant_t object of type VT_BSTR from a _bstr_t object. A new BSTR is allocated.

  • _variant_t( wchar_t *wstrSrc )   Constructs a _variant_t object of type VT_BSTR from a Unicode string. A new BSTR is allocated.

  • _variant_t( char* strSrc )   Constructs a _variant_t object of type VT_BSTR from a string. A new BSTR is allocated.

  • _variant_t( bool bSrc )   Constructs a _variant_t object of type VT_BOOL from a bool value.

  • _variant_t( IUnknown* pIUknownSrc, bool fAddRef = true )   Constructs a _variant_t object of type VT_UNKNOWN from a COM interface pointer. If fAddRef is true, then AddRef is called on the supplied interface pointer to match the call to Release that will occur when the_variant_t object is destroyed. It is up to you to call Release on the supplied interface pointer. If fAddRef is false, this constructor takes ownership of the supplied interface pointer; do not call Release on the supplied interface pointer.

  • _variant_t( IDispatch* pDispSrc, bool fAddRef = true )   Constructs a _variant_t object of type VT_DISPATCH from a COM interface pointer. If fAddRef is true, then AddRef is called on the supplied interface pointer to match the call to Release that will occur when the_variant_t object is destroyed. It is up to you to call Release on the supplied interface pointer. If fAddRef is false, this constructor takes ownership of the supplied interface pointer; do not call Release on the supplied interface pointer.

  • _variant_t( DECIMAL& decSrc )   Constructs a _variant_t object of type VT_DECIMAL from a DECIMAL value.

  • _variant_t( BYTE bSrc )   Constructs a _variant_t object of type VT_UI1 from a BYTE value.

下面是一个标准用法,创建时指定property类型为short,设置数值时指定property类型为short.

// 创建property
CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("透明度"), _variant_t((short), VT_I2), _T("填充透明度0-100"));
pProp->EnableSpinControl(TRUE, , );
pGroup3->AddSubItem(pProp); //设置property数值
sProp->SetValue(_variant_t((short)(sp->mFillTransparency * ), VT_I2));

CMFCPropertyGridProperty SetValue 出错处理的更多相关文章

  1. CMFCPropertyGridProperty用法

    MFCPropertyGridCtrl 是VC 2008 pack中的控件类. CMFCPropertyGridProperty这个控件类中的属性值类类. 针对修改属性后,对属性值改变的消息处理: 方 ...

  2. 使用野狗(Wilddog)云setValue写入数据

    - (void)viewDidLoad { [super viewDidLoad]; //创建野狗实例化对象 用于随时监听数值变化 Wilddog *myRootRef = [[Wilddog all ...

  3. setValue:forUndefinedKey this class is not key value coding-compliant for the key

    下午开发过程中遇到一个错误,结果被的真惨,从上午 11 点查错一直查到下午 2 点才找到错误的原因,真的郁闷的不行. 关于查错这么久,主要的原因是:   1. 自己对 IOS 开发还不熟悉2. 不知道 ...

  4. reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key value c

    reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key v ...

  5. IOS setValue forKey

    NSObjiect *obj:[obj setValue:value forKey:@"cpname"]复制代码的时候都会出现这个异常this class is not key v ...

  6. NSMutableDictionary中 setValue和setObject的区别

    对于- (void)setValue:(id)value forKey:(NSString *)key;函数 官方解释如下 Send -setObject:forKey: to the receive ...

  7. setValue和setObject的区别

    在NSMutableDictionary的方法中有setValue forKey与setObject forKey,它们都可以用来设置某一个key值对应的value 1,setValue: forKe ...

  8. 【Visual Lisp】两种出错处理方式

    两种出错处理方式:一种是对出错函数进行重定义,一种是对错误进行捕捉处理. ;;============================================================= ...

  9. '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]

    Bug如下: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUnd ...

随机推荐

  1. inux grep 命令 搜索含有"zynq"字符的文件

    使用命令grep -rl 'zynq' /work/xilinx/u-boot-xlnx-master (有引号)-r 选项表示递归(recursive)遍历所有子目录-l 选项表示只列出文件名 /w ...

  2. JS获取form表单所有属性值

    // 得到一个表单里的全部信息function getFormQueryString() { var frmID=document.forms[0]; var i,queryString=" ...

  3. 高斯模糊算法的 C++ 实现

    2008 年在一个 PS 讨论群里,有网友不解 Photoshop 的高斯模糊中的半径是什么含义,因此当时我写了这篇文章: 对Photoshop高斯模糊滤镜的算法总结: 在那篇文章中,主要讲解了高斯模 ...

  4. Access restriction错误解决办法

    Access restriction错误, XX方法 is not accessible due to restriction on required library XXlib 解决方案: Ecli ...

  5. 1、win32创建窗口函数(windows程序内部运行机制)

    利用win32创建窗口函数,主要操作步骤为: 1.设计一个窗口类 2.注册窗口类 3.创建窗口 4.显示及窗口更新 5.消息循环 6.窗口过程函数   (1)设计一个窗口类 设计窗口类,这样的类型已经 ...

  6. PL/SQL Developer 和 instantclient客户端安装配置(图文)

    一: PL/SQL Developer 安装 下载安装文件安装,我这里的版本号是PLSQL7.1.4.1391,安装目录是:D:\soft\PLSQLDeveloper 二:instantclient ...

  7. BroadCast小结

    1.BroadCast注册方式 静态注册:即在AndroidManifest.xml 文件中定义 <receiver android:name=".BroadCastB"&g ...

  8. xml 配置文件规范 校验

    背景:做的数据同步框架,数据同步种类通过xml配置文件添加.为了系统的稳定性,我们只能认为将来写这个运行配置xml的人是一个傻瓜,那么对xml格式校验就很重要. 通过dom4j,是可以完成对xml格式 ...

  9. Swift 3 中的访问控制 open public internal fileprivate private

    Swift 3必看:新的访问控制fileprivate和open http://www.jianshu.com/p/604305a61e57 浅谈 Swift 3 中的访问控制 https://mai ...

  10. Leetcode2:Add Two Numbers@Python

    You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...