对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. 剖析JavaScript函数作用域与闭包

    在我们写代码写到一定阶段的时候,就会想深究一下js,javascript是一种弱类型的编程语言,而js中一个最为重要的概念就是执行环境,或者说作用域.作用域重要性体现在哪呢?首先,函数在执行时会创建作 ...

  2. WGS84经纬度坐标与北京54坐标或者西安80坐标的关系

    一般来讲,GPS直接提供的坐标(B,L,H)是1984年世界大地坐标系(WordGeodetic System 1984即WGS-84)的坐标,其中B为纬度,L为经度,H为大地高即是到WGS-84椭球 ...

  3. 调用 SSPI 失败,请参见内部异常。接收到的消息异常,或格式不正确。

    完整异常信息: System.Security.Authentication.AuthenticationException: 调用 SSPI 失败,请参见内部异常. ---> System.C ...

  4. 线程,yield让出cpu调度

    public class Yield01 extends Thread { public static void main(String[] args) { new Yield01().start() ...

  5. C++设计模式-Composite组合模式

    Composite组合模式作用:将对象组合成树形结构以表示“部分-整体”的层次结构.Composite使得用户对单个对象和组合对象的使用具有一致性. UML图如下: 在Component中声明所有用来 ...

  6. 用 pyvenv 创建几个不相互影响的python虚拟环境

    IN MY UBUNTU python2的环境控制: sudo apt-get install virtualenv 创建: virtualenv --no-site-packages  [环境搭建目 ...

  7. ASP.NET权限管理

    ASP.NET Web Forms权限管理: 我要将一个文件夹只能让一个用户组访问怎么办? 可否在网站根目录下的web.config里这样设置: <location path="adm ...

  8. CSS3中-webkit-overflow-scrolling: touch 的使用方法详解

    -webkit-overflow-scrolling 属性控制元素在移动设备上是否使用滚动回弹效果. auto 使用普通滚动, 当手指从触摸屏上移开,滚动会立即停止. touch 使用具有回弹效果的滚 ...

  9. Ax 导出EXCEL给范围内的每个单元格加边框

    1. 首先在Class\SysExcelRange加画边框的方法 思路用EXCEL录宏的功能得到给一批单元格画格子的VBA代码,在AX将对象转为COM对象,基本VBA代码也能装为AX内能用的内容. p ...

  10. jQuery判断键盘按下的keyCode

    $("div").keydown(function(event) { var keyCode = event.keyCode; //根据keycode判断按下的是哪个键 });