typeinfo

How to know what type is a var?

TypeInfo(Type) returns the info about the specified type, is there any way to know the typeinfo of a var? var S: string; Instance: IObjectType; Obj: TDBGrid; Info: PTypeInfo; begin Info:= TypeInfo(S); Info:= TypeInfo(Instance); Info:= TypeInfo(Obj); end This code returns: [DCC Error] Unit1.pas(354): E2133 TYPEINFO stand...

String representation of the content type of a Variant ?

Hi, first apologies for my english, I hope it make sense what I`ve wrote here. Now to my problem. How can I get the string representation of the content type of a Variant using TypInfo.GetEnumName(). I have tried the following, without luck, i get a numeric representation. myString := GetEnumName( TypeInfo(TVarType), TVarData(myVar).V...

Get TypeInfo in static constructor.

Is there any way to get the equivalent of GetType within a static constructor? I want to iterate through the available properties of the type within the static constructor but GetType is an instance method? Why is this? The typeinfo should exist in the static context. Is there a way around this?? ~ Cameron ...

Why do I get "type has no typeinfo" error with an enum type

I have declared the following enum type in which I want the first member to have the ordinal value of 1 (one) rather than the usual 0 (zero): type TMyEnum = ( meFirstValue = 1, meSecondValue, meThirdValue ); If I call TypeInfo(), e.g. as part of a call to GetEnumName(), ...

What's the lifetime of memory pointed to typeinfo::name()?

In C++ I can use typeid operator to retrieve the name of any polymorphic class: const char* name = typeid( CMyClass ).name(); How long will the string pointed to by the returned const char* pointer available to my program? ...

storing a type's type for processing variable argument lists

Is it possible to do something along the lines of: type t = int;//this would be a function which identifies what type the next argument is if( t == int ) printf( "%d", va_arg( theva_list, t ) ); in a relatively trivial way? The only object I know which can hold a type is type_info and I can't work out how to use it in this way. T...

How To Get Type Info Without Using Generics?

Hi Guys I have an object obj that is passed into a helper method. public static MyTagGenerateTag<T>(this HtmlHelper htmlHelper, T obj /*, ... */) { Type t = typeof(T); foreach (PropertyInfo prop in t.GetProperties()) { object propValue = prop.GetValue(obj, null); string stringValue = propValue.ToString(); ...

C++ template name pretty print

hello. I have need to print indented template names for debugging purposes. For example, instead of single-line, I would like to indent name like this: boost::phoenix::actor< boost::phoenix::composite< boost::phoenix::less_eval, boost::fusion::vector< boost::phoenix::argument<0>, boost::phoenix::argument<...

g++ linker error--typeinfo, but not vtable

I know the standard answer for a linker error about missing typeinfo usually also involves vtable and some virtual function that I forgot to actually define. I'm fairly certain that's not the situation this time. Here's the error: UI.o: In function boost::shared_ptr<Graphics::Widgets::WidgetSet>::shared_ptr<Graphics::Resource::GroupBy...

Enumerated types with specified values do not have TypeInfo, why?

Using Delphi 2007 I can write the following code: interface TTestType = (ttTest1, ttTest2); procedure enumName; var EnumName: String; begin EnumName := GetEnumName(TypeInfo(TTestType), Ord(ttTest1)); end; This compiles and works, EnumName contains 'ttTest1' at the end of the function. However, when I change my TTestType to somet...

Will C++0x provide hashing functions for std::type_info?

Hello everyone :) I'm still working on a good solution to my One-Of-A-Type Container Problem -- and upon reflection I think it would be nice to be able to just use something like a std::map<std::type_info, boost::any>. Unfortunately, std::type_info does not define an operator<, and I think it'd be unreasonable for it to define one. How...

How can I get element type (e.g. float) and attributes (e.g. MaxOccurs) from an XML file & corresponding XSD?

I need to be able to take an XML file and corresponding XSD at runtime and derive an array of elements and associated attributes. I've seen a few posts e.g.: http://www.java2s.com/Code/Java/XML/ProvidesatraceoftheschematypeinformationforelementsandattributesinanXMLdocument.htm that suggest using a sax parser to iterate through the do...

Getting type of an object

I'm trying to do something along these lines: int var = 5; std::numeric_limits<typeid(var)>::max(); but surprise, surprise it doesn't work. How can I fix this? Thanks. ...

trying to count instances of deriving classes, type_id doesnt work

first of all i think its a crapy design , but im trying to prove a point. i want to count all the instances of derivers from my class, im trying to do it like so: .h file: #ifndef _Parant #define _Parant #include<map> class Parant { public: Parant(); virtual ~Parant(); static void PrintInstances(); private: static v...

Why is std::type_info polymorphic?

Is there a reason why std::type_info is specified to be polymorphic? The destructor is specified to be virtual (and there's a comment to the effect of "so that it's polymorphic" in The Design and Evolution of C++). I can't really see a compelling reason why. I don't have any specific use case, I was just wondering if there ever was a rat...