CMFCPropertyGridProperty SetValue 出错处理
对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_I4, VT_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 出错处理的更多相关文章
- CMFCPropertyGridProperty用法
MFCPropertyGridCtrl 是VC 2008 pack中的控件类. CMFCPropertyGridProperty这个控件类中的属性值类类. 针对修改属性后,对属性值改变的消息处理: 方 ...
- 使用野狗(Wilddog)云setValue写入数据
- (void)viewDidLoad { [super viewDidLoad]; //创建野狗实例化对象 用于随时监听数值变化 Wilddog *myRootRef = [[Wilddog all ...
- setValue:forUndefinedKey this class is not key value coding-compliant for the key
下午开发过程中遇到一个错误,结果被的真惨,从上午 11 点查错一直查到下午 2 点才找到错误的原因,真的郁闷的不行. 关于查错这么久,主要的原因是: 1. 自己对 IOS 开发还不熟悉2. 不知道 ...
- reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key value c
reason: '[<__NSDictionary0 0x7fda88f00c90> setValue:forUndefinedKey:]: this class is not key v ...
- IOS setValue forKey
NSObjiect *obj:[obj setValue:value forKey:@"cpname"]复制代码的时候都会出现这个异常this class is not key v ...
- NSMutableDictionary中 setValue和setObject的区别
对于- (void)setValue:(id)value forKey:(NSString *)key;函数 官方解释如下 Send -setObject:forKey: to the receive ...
- setValue和setObject的区别
在NSMutableDictionary的方法中有setValue forKey与setObject forKey,它们都可以用来设置某一个key值对应的value 1,setValue: forKe ...
- 【Visual Lisp】两种出错处理方式
两种出错处理方式:一种是对出错函数进行重定义,一种是对错误进行捕捉处理. ;;============================================================= ...
- '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]
Bug如下: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUnd ...
随机推荐
- redis中setbit的用法
原文地址:http://www.zhihu.com/question/27672245 在redis中,存储的字符串都是以二级制的进行存在的.举例:设置一个 key-value ,键的名字叫“andy ...
- Java里Serializable的那些事
本文为原创文章,欢迎转载,但请注明出处http://www.cnblogs.com/yexiubiao/p/5014015.html,未在文章页面明显位置给出原文连接的,将保留追究法律责任的权利. 通 ...
- 使用Starling 框架时,报错Error: Error #3669: 输入大小错误, 解决方案
原因有二:1.IE底下,SWFOBJECT嵌入swf的时候,有瞬间的stage的width跟height是0导致的.2.stage.scaleMode = StageScaleMode.NO_SCAL ...
- 【原创翻译】初识Unity中的Compute Shader
一直以来都想试着自己翻译一些东西,现在发现翻译真的很不容易,如果你直接把作者的原文按照英文的思维翻译过来,你会发现中国人读起来很是别扭,但是如果你想完全利用中国人的语言方式来翻译,又怕自己理解的不到位 ...
- 关于Lucene.net 中高亮显示关键词的深究
这几天一直在学习lucene,也写了3篇自己总结的知识点,本以为很容易上手的东西,但是却遇到了一个很棘手的问题,借此,希望可以跟大家探讨一下 问题:使用盘古高亮显示组件后,如搜索“mp3 player ...
- NodeJs 创建 Web 服务器
以下是演示一个最基本的 HTTP 服务器架构(使用8081端口),创建 ser.js 文件,代码如下所示: var http = require('http'); var fs = require(' ...
- 使用BigDecimal进行精确运算
首先我们先来看如下代码示例: 1 public class Test_1 { 2 public static void main(String[] args) { 3 System.out.print ...
- Tcp/IP
在数据传输完毕之后,通信双方都可以发出释放连接的请求.释放连接的过程为如上图所示: 1)数据传输结束后,主机A的应用进程先向其TCP发出释放连接请求,不在发送数据.TCP通知对方要释放从A ...
- Tomcat日志切割
下载并解压缩 cronolog # tar zxvf cronolog-1.6.2.tar.gz 2.进入cronolog安装文件所在目录 # cd cronolog-1.6.2 3.运行安装 # ...
- ZeroC Ice 暂记
摘自: http://weibo.com/p/1001603869896789339575 原文地址: http://www.oschina.net/question/865233_242146 吴治 ...