将OleVariant与UnAssigned比较时无效的变体运算 [英] Invalid Variant Operation when comparing an OleVariant to UnAssigned

查看:169
本文介绍了将OleVariant与UnAssigned比较时无效的变体运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

**if** FWordApp = UnAssigned **then**
    FWordApp := CreateOleObject('Word.Application') ;
Result := FWordApp;

以上内容位于GETter中,表示类型为OleVariant的属性.

The above sits in a GETter for a property of type OleVariant.

第一次通过,将TRUE与Unassigned比较. 但是,第二次情况并非如此,与未分配相比,这给我带来了无效的变体运算错误.

The first time, it goes through fine, compares TRUE to Unassigned. However, the same isn't true the second time, where comparing to UnAssigned gives me an Invalid Variant Operation error.

推荐答案

错误消息告诉您,不允许您在OleVariant上下文中将Unassigned与COM对象进行比较.那是非法的比较.

As the error message is telling you, you are not allowed to compare Unassigned against a COM object in the context of an OleVariant. That's an illegal comparison.

您的测试应改为使用VarIsEmpty:

if VarIsEmpty(FWordApp) then
  FWordApp := CreateOleObject('Word.Application');

这篇关于将OleVariant与UnAssigned比较时无效的变体运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆