variant

Passing an object from C++ to C# though COM

末鹿安然 提交于 2019-12-10 16:04:22
问题 hi have a COM visible API in C# which looks like the following: public void DoSomething(string par1, string par2, object additionalParameter) The idea is that based on the value of the string parameters I expect a different class as the third parameter and cast it appropriately in the implementation (I know this design is not optimal but I don't have much flexibility here). Suppose that for some combination of the string parameters the type of the additional parameter is the following:

How to convert string type array to variant type array - Excel VBA

喜你入骨 提交于 2019-12-10 14:05:00
问题 I am attempting to load formulae stored in a tab-delimited text file into a range in a worksheet. I have used the function Split(Expression As String, Delimiter) to correctly load each line in turn into a 1D array, but have run into problems concerning the array type returned. The Split function only returns string type arrays, and I need a variant type array to set the range to. This is because setting the formulae of cells using a string type array causes the cell values to be set to the

Why can't Delphi variants hold objects?

自闭症网瘾萝莉.ら 提交于 2019-12-09 09:03:54
问题 Why can't Delphi variants hold objects? More importantly, what's the reason behind this limitation? 回答1: This is just an opinion, from my experience with what variants can and cannot do. If you put a COM object into it, it will be stored as an IDispatch reference, and thus any method calls or properties you access on this object will be converted into some code that looks up the internal DISPID of the method/property, an array with method arguments will be constructed, and the method will be

Why does assigning a single to a variant result in a varDouble variant?

穿精又带淫゛_ 提交于 2019-12-08 16:31:49
问题 uses SysUtils, Variants; var VariantSingle: Variant; VTSingle: TVarType; SingleTest: Single; VariantDouble: Variant; DoubleTest: Double; VTDouble: TVarType; begin SingleTest := 1.234; VariantSingle := SingleTest; VTSingle := VarType(VariantSingle) and varTypeMask; DoubleTest := 1.23456; VariantDouble := DoubleTest; VTDouble := VarType(VariantDouble) and varTypeMask; WriteLn(Format('VarType: Single: %d, Double %d', [VTSingle, VTDouble])); end. The code above will output: VarType: Single: 5,

Does using single-case discriminated union types have implications on performance?

蓝咒 提交于 2019-12-08 15:41:03
问题 It is nice to have a wrapper for every primitive value, so that there is no way to misuse it. I suspect this convenience comes at a price. Is there a performance drop? Should I rather use bare primitive values instead if the performance is a concern? 回答1: Yes, there's going to be a performance drop when using single-case union types to wrap primitive values. Union cases are compiled into classes, so you'll pay the price of allocating (and later, collecting) the class and you'll also have an

conversion between std::vector and _variant_t

社会主义新天地 提交于 2019-12-08 05:02:48
问题 I need to convert between std::vector and _variant_t to avoid looping when writing/sending data into some file (database, Excel, etc.) Could you please let me know how to proceed with that? I was trying to get a std::vector<_variant_t> and somehow put into another _variant_t variable, but direct conversion is not supported and even if it's done there's no either method or some kind of wrapper to get this vector into a _variant_t variable. I would prefer not to deal with any loops. 回答1: A std:

Cast object as OleVariant in Delphi

旧巷老猫 提交于 2019-12-07 17:20:24
问题 Is there a way to pass a wrap and unwrap a TObject descendent in an OleVariant? I am trying to pass a TObject across automation objects. I know it's not a good idea but I don't have a good alternative. The object is to be passed between objects from the same automation dll, if that makes any difference. Something like this: function GetMyObjAsVariant; var MyObj: TMyObj; begin MyObj := TMyObj.Create; result := OleVariant(MyObj); end; Which would be used by a client as var MyObj: TMyObj; begin

Iterator for boost::variant

泄露秘密 提交于 2019-12-07 10:10:30
问题 Hy there, I'm trying to adapt an existing code to boost::variant. The idea is to use boost::variant for a heterogeneous vector. The problem is that the rest of the code use iterators to access the elements of the vector. Is there a way to use the boost::variant with iterators? I've tried typedef boost::variant<Foo, Bar> Variant; std::vector<Variant> bag; std::vector<Variant>::iterator it; for(it= bag.begin(); it != bag.end(); ++it){ cout<<(*it)<<endl; } But it didn't work. EDIT: Thank you for

Convert Variant Array to String

依然范特西╮ 提交于 2019-12-07 01:24:54
问题 I am trying to take a variant variable and convert it into a string so that I can run a split function on the data. However, whenever I try to redefine the variant I get a type mismatch error. I have used the CStr(), Str(), and ToString functions. None work. Anything I am missing? Function FlatLine(ByVal lines As Variant) Dim flat() As String ReDim Preserve flat(i) For i = 0 To UBound(lines) flat(UBound(flat)) = lines(i) ReDim Preserve flat(LBound(flat) To UBound(flat) + 1) Next i Dim flat2

Return type std::optional<std::variant<…>>

白昼怎懂夜的黑 提交于 2019-12-06 23:33:31
问题 I have a situation where a function must return a value taken from a table. A cell in this table (let's assume the table just works...) may contain a value, or it might not. This value can also be one of several types: int, double, string, date (but no other type). What would such a function return? Is it a good idea to return std::optional<std::variant<std::string, int, double, std::chrono::time_point>> ? Would that be a good use of optional and variant ? 回答1: I would consider this to be a