如何使用 rtti 将 NULL 设置为 Variant 字段

发布于 2024-08-20 05:08:31 字数 537 浏览 3 评论 0原文

我在使用 rtti 将变体字段设置为 null 时遇到问题。

假设我有这样的类:

TClass1 = class
  Field1:Integer;  
  Field2:Variant; 
end;

当我访问 Field1 时,我可以执行以下操作:

Field.SetValue(TObject(ValueObject.AsObject), 1);

但似乎我无法使用 Field2 执行此操作:

Field.SetValue(TObject(ValueObject.AsObject), null);

或者

Field.SetValue(ValueObject.AsObject, TValue.FromVariant(NULL));

所以,我想要的是能够将 null 值设置为上面类的 Field2。是否可以?任何想法将不胜感激。

戈兰

I have a problem setting null to a variant field using rtti.

Suppose I have class like this:

TClass1 = class
  Field1:Integer;  
  Field2:Variant; 
end;

when I get access to a Field1 I can do:

Field.SetValue(TObject(ValueObject.AsObject), 1);

but it seems I can not do this with Field2:

Field.SetValue(TObject(ValueObject.AsObject), null);

or

Field.SetValue(ValueObject.AsObject, TValue.FromVariant(NULL));

So, what I want is to be able to set null value to a Field2 of class above. Is it possible? Any ideas would be appreciated.

Goran

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兲鉂ぱ嘚淚 2024-08-27 05:08:31

这有效:

Field.SetValue(Self, TValue.From<Variant>(Null) );

This works:

Field.SetValue(Self, TValue.From<Variant>(Null) );
梦里°也失望 2024-08-27 05:08:31

这看起来是我在回答 这个问题。 SetValue 无法正确处理某些数据类型的“空”值。我将用新案例更新质量控制报告。因此,目前您还不能,至少在不亲自修补 RTTI 单元的情况下不能。

This looks to be another manifestation of the bug I found while answering this question. SetValue doesn't handle "empty" values correctly for certain data types. I'll update the QC report with the new case. So, for the moment, you can't, at least not without patching the RTTI unit yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文