OLE variants used by older versions of Visual Basic and distributed in COM Automation can store many different types: basic types, such as integers and float, more complex types, such as strings and arrays, and up to IDispatch implementations and pointers as variants ByRef
Variants are also weakly typed: they convert the value to another type without warning, depending on which operator you are using and what current types have values passed to the operator. For example, comparing two options, one of which contains an integer 1 and the other containing the string "1" , for equality will return True .
Therefore, assuming that I am working with options at the basic data level (for example, VARIANT in C ++ or TVarData in Delphi, i.e. in a large pool of different possible values), how should I use hash options sequentially so that they comply right rules?
Rules:
- Options that hash unevenly compare both unequal, both in sorting and in direct equality
- Options that are compared as equals for sorting and direct equality must have a hash as equal
This is fine if I need to use different sorting and direct comparison rules to make hashing suitable.
The way I am working now, I normalize options to strings (if they fit) and treat them like strings, otherwise I work with the variant data as if it were an opaque blob, and hashing and comparing its raw bytes. Of course, this has some limitations: the numbers 1..10 are sorted as [1, 10, 2, ... 9] , etc. It is slightly annoying, but it is consistent, and it is very small. However, I really wonder if there is an accepted practice for this problem.
c ++ winapi delphi com variant
Barry kelly
source share