如何获取TValue的类型?

问题描述 投票:0回答:1

我需要获取一个 TValue.

TControl *control = MyForm->Controls[1337];
TRttiContext ctx;
TRttiType *type = ctx.GetType(control->ClassInfo());
TRttiProperty *property = type->GetProperty("Text"); // or "Caption", etc.
TValue result = property->GetValue(control);

if (result.IsType(tkUString)) {  
    std::cout << "String!" << std::endl;
else 
    std::cout << "NOT String!" << std::endl;

我得到以下错误。

[bcc64 Error] Unit1.cpp(142): no matching member function for call to 'IsType'
System.Rtti.hpp(323): candidate function not viable: no known conversion from 'System::TTypeKind' to 'System::Typinfo::PTypeInfo' (aka 'System::Typinfo::TTypeInfo *') for 1st argument

看一下... 文件 IsType() 需要 PTypeInfo 论点 tkUString 不是)。)

但是没有C++文档中关于 PTypeInfo惟有 德尔菲.

我必须在我的项目中包含一个Delphi单元,才能使用 TValue.IsType()?

c++builder rtti
1个回答
0
投票

我用错了方法。

这是错的。

if (result.IsType(tkUString)) {  

这是对的

if (result.Kind == tkUString) {
© www.soinside.com 2019 - 2024. All rights reserved.