class RTL_DELPHIRETURN Variant: public TVarData

Variant转换为字符串
 System::Variants::VarToStr

VariantArrays,

VarArrayCreate
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant array;
int bounds[] = {, }; /*
Create a variant array of 10 elements, starting at 0
and ending at 9. The array contains elements of type integer.
*/
array = VarArrayCreate(bounds, , varInteger); // Increase the length of the variant array.
VarArrayRedim(array, ); MessageDlg(String("Variant array has ") + IntToStr(VarArrayDimCount(array)) +
" dimensions", mtInformation, TMsgDlgButtons() << mbOK, ); // Traverse the array from lower to higher bounds.
for (int i = VarArrayLowBound(array, ); i <= VarArrayHighBound(array, ); i++)
{
// Put the element I at index I.
VarArrayPut(array, i, &i, );
} // Now read the elements of the array.
for (int i = VarArrayLowBound(array, ); i <= VarArrayHighBound(array, ); i++)
{
// Put the element I at index I.
if (VarArrayGet(array, &i, ) != i)
MessageDlg("Error! Invalid element found at current position!",
mtError, TMsgDlgButtons() << mbOK, );
} // Clear the variant array.
VarClear(array);
}
VarToStr
VarToStrDef
VarToWideStr
VarToWideStrDef
VarToDateTime

VType


void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant V;
String mystr;
if (TVarData(V).VType == varEmpty)
ListBox1->Items->Add(L"Variants start મઽૠ૪ empty.");
VarClear(V);
TVarData(V).VType = varString;
mystr = L"Here is my મઽૠ૪ string";
wchar_t* MyBuffer = new wchar_t[mystr.Length() + ];
StrCopy(MyBuffer, mystr.c_str());
TVarData(V).VString = MyBuffer;
mystr = (wchar_t *)(TVarData(V).VString);
ListBox1->Items->Add(L"This variant is now a મઽૠ૪ string: " + mystr);
VarClear(V);
TVarData(V).VType = varInteger;
TVarData(V).VInteger = ;
ListBox1->Items->Add(L"This variant is now an મઽૠ૪ integer: " + IntToStr(TVarData(V).VInteger));
}

TVarData(V).VBoolean;

Variant Type

TParam *p;
  p->Value.VBoolean;
  this->FDQuery1->FieldByName("")->Value.VBoolean;

 V.VType = varInteger;
V.VInteger = 1234567;
    Variant V;
TVarData( V ).VType = varBoolean;
TVarData( V ).VBoolean = True;
this->Caption = V;

d:\program files (x86)\embarcadero\studio\16.0\include\windows\rtl\systvar.h

// TVarData = VARIANT
struct TVarData
{
union
{
uint16_t VType; // Delphi-compatible - Variant Type member
#if defined(VARIANT_NATIVE_SUPPORT)
VARTYPE vt; // tagVARIANT compatible member
#else
uint16_t vt; // Expose a generic 'vt' member
#endif
};
uint16_t Reserved1;
uint16_t Reserved2;
uint16_t Reserved3;
union
{
// Delphi-compatible TVarData/Variant members
System::Smallint VSmallint; // iVal
System::Integer VInteger; // lVal
System::Single VSingle; // fltVal
System::Double VDouble; // dblVal
System::CurrencyBase VCurrency; // cyVal
System::TDateTimeBase VDate; // date
System::PWideChar VOleStr; // bstrVal
#ifdef _WIN32
IDispatch* VDispatch; // pdispVal
#else
System::IDispatch* VDispatch; // pdispVal
#endif
System::HResult VError; // scode
System::WordBool VBoolean; // boolVal
IUnknown* VUnknown; // punkVal
System::Byte VByte; // bVal
System::Int8 VShortint; // charVal
System::Int8 VShortInt; // charVal
System::Pointer VString; // ??????
System::PVarArray VArray; // parray
System::Pointer VPointer; // byref
__int64 VInt64; // llVal
unsigned __int64 VUInt64; // ullVal
System::Word VWord; // uiVal
System::LongWord VLongWord; // ulVal
System::TVarRecord VRecord; // struct __tagBRECORD
}

d:\program files (x86)\embarcadero\studio\16.0\include\windows\rtl\System.hpp

 Int8 varEmpty = Int8(0x0);
Int8 varNull = Int8(0x1);
Int8 varSmallint = Int8(0x2);
Int8 varInteger = Int8(0x3);
Int8 varSingle = Int8(0x4);
Int8 varDouble = Int8(0x5);
Int8 varCurrency = Int8(0x6);
Int8 varDate = Int8(0x7);
Int8 varOleStr = Int8(0x8);
Int8 varDispatch = Int8(0x9);
Int8 varError = Int8(0xa);
Int8 varBoolean = Int8(0xb);
Int8 varVariant = Int8(0xc);
Int8 varUnknown = Int8(0xd);
Int8 varShortInt = Int8(0x10);
Int8 varByte = Int8(0x11);
Int8 varWord = Int8(0x12);
Int8 varLongWord = Int8(0x13);
Int8 varInt64 = Int8(0x14);
Int8 varUInt64 = Int8(0x15);
Int8 varRecord = Int8(0x24);
Int8 varStrArg = Int8(0x48);
Int8 varObject = Int8(0x49);
Int8 varUStrArg = Int8(0x4a);
Word varString = Word(0x100);
Word varAny = Word(0x101);
Word varUString = Word(0x102);
Word varTypeMask = Word(0xfff);
Word varArray = Word(0x2000);
Word varByRef = Word(0x4000);
Int8 vtInteger = Int8(0x0);
Int8 vtBoolean = Int8(0x1);
Int8 vtChar = Int8(0x2);
Int8 vtExtended = Int8(0x3);
Int8 vtString = Int8(0x4);
Int8 vtPointer = Int8(0x5);
Int8 vtPChar = Int8(0x6);
Int8 vtObject = Int8(0x7);
Int8 vtClass = Int8(0x8);
Int8 vtWideChar = Int8(0x9);
Int8 vtPWideChar = Int8(0xa);
Int8 vtAnsiString = Int8(0xb);
Int8 vtCurrency = Int8(0xc);
Int8 vtVariant = Int8(0xd);
Int8 vtInterface = Int8(0xe);
Int8 vtWideString = Int8(0xf);
Int8 vtInt64 = Int8(0x10);
Int8 vtUnicodeString = Int8(0x11);
Int8 vmtArcOffset = Int8(0x0);

_VarToUStr

参考官方的写法

procedure _VarToUStr(var S: UnicodeString; const V: TVarData);
begin
case V.VType of
varEmpty: S := '';
varNull:
begin
if NullStrictConvert then
VarCastError(varNull, varOleStr);
S := NullAsStringValue;
end;
varSmallInt: S := IntToStr(V.VSmallInt);
varInteger: S := IntToStr(V.VInteger);
varSingle: S := FloatToStr(V.VSingle);
varDouble: S := FloatToStr(V.VDouble);
varShortInt: S := IntToStr(V.VShortInt);
varByte: S := IntToStr(V.VByte);
varWord: S := IntToStr(V.VWord);
varLongWord: S := UIntToStr(V.VLongWord);
varInt64: S := IntToStr(V.VInt64);
varUInt64: S := UIntToStr(V.VUInt64); varVariant: _VarToUStr(S, PVarData(V.VPointer)^);
varOleStr: S := Copy(WideString(Pointer(V.VOleStr)), , MaxInt); {$IFNDEF NEXTGEN}
varCurrency: S := CurrToWStrViaOS(V.VCurrency);
varDate: S := DateToWStrViaOS(V.VDate);
varBoolean: S := BoolToWStrViaOS(V.VBoolean);
varDispatch,
varUnknown: S := VarToWStrViaOS(V);
{$ELSE} varCurrency: S := CurrToStr(V.VCurrency);
varDate: S := DateTimeToStr(V.VDate);
varBoolean: S := BoolToStr(V.VBoolean,True); {$ENDIF !NEXTGEN}
else
case V.VType of
varString: S := RawByteString(V.VString);
varUString: S := UnicodeString(V.VUString);
varAny: S := VarToUStrAny(V);
else
if V.VType and varByRef <> then
case V.VType and not varByRef of
varSmallInt: S := IntToStr(PSmallInt(V.VPointer)^);
varInteger: S := IntToStr(PInteger(V.VPointer)^);
varSingle: S := FloatToStr(PSingle(V.VPointer)^);
varDouble: S := FloatToStr(PDouble(V.VPointer)^);
varShortInt: S := IntToStr(PShortInt(V.VPointer)^);
varByte: S := IntToStr(PByte(V.VPointer)^);
varWord: S := IntToStr(PWord(V.VPointer)^);
varLongWord: S := UIntToStr(PCardinal(V.VPointer)^);
varInt64: S := IntToStr(PInt64(V.VPointer)^);
varUInt64: S := UIntToStr(PUInt64(V.VPointer)^);
varVariant: _VarToUStr(S, PVarData(V.VPointer)^);
{$IFNDEF NEXTGEN}
varCurrency: S := CurrToWStrViaOS(PCurrency(V.VPointer)^);
varDate: S := DateToWStrViaOS(PDate(V.VPointer)^);
varOleStr: S := PWideChar(V.VPointer^);
varBoolean: S := BoolToWStrViaOS(PWordBool(V.VPointer)^);
varString: S := UnicodeString(PAnsiChar(V.VPointer^));
varUString: S := PWideChar(V.VPointer^);
else
S := VarToWStrViaOS(V);
{$ELSE NEXTGEN}
varCurrency: S := CurrToStr(PCurrency(V.VPointer)^);
varDate: S := DateTimeToStr(PDate(V.VPointer)^);
varOleStr: S := Copy(PChar(V.VPointer^), , MaxInt);
varBoolean: S := BoolToStr(PWordBool(V.VPointer)^);
varUString: S := PWideChar(V.VPointer^); {$ENDIF NEXTGEN}
end
else
if not VarToUStrCustom(V, S) then
{$IFNDEF NEXTGEN}
S := VarToWStrViaOS(V);
{$ELSE NEXTGEN} ; // Now we do nothing
{$ENDIF !NEXTGEN}
end;
end;
end;

Variant的更多相关文章

  1. VCF (Variant Call Format)格式详解

    文章来源:http://www.cnblogs.com/emanlee/p/4562064.html VCF文件示例(VCFv4.2) ##fileformat=VCFv4.2 ##fileDate= ...

  2. Android Gradle 技巧之一: Build Variant 相关

    Build Variant android gradle 插件,允许对最终的包以多个维度进行组合. BuildVariant = ProductFlavor x BuildType 两个维度 最常见的 ...

  3. C++使用VARIANT实现二维数组的操作

    C++使用VARIANT实现二维数组的操作 VARIANT变量是COM组件之间互相通信的重要的参数变量之一,它可以容纳多种不同的类型,如short.long.double等,包括各类指针和数组.组件之 ...

  4. Variant OLE automation

    The Variant data type is the data type for all variables. can contain any kind of data except fixed- ...

  5. 实现一个 Variant

    很多时候我们希望能够用一个变量来保存和操作不同类型的数据(比如解析文本创建 AST 时保存不同类型的结点),这种需求可以通过继承来满足,但继承意味着得使用指针或引用,除了麻烦和可能引起的效率问题,该做 ...

  6. duilib\utils\utils.h(251) : error C2504: “VARIANT”: 未定义基类

    转载:http://blog.csdn.net/SP_daiyq/article/details/44542939?locationNum=3 创建win32应用程序的工程文件,删除不需要的代码,只留 ...

  7. VKP5 Price Calculation – List Variant & KZPBL (Delete site level)

    List Variant: Configuration in Logistic General –> Retail Pricing –> Sales Price Calculation – ...

  8. C++ VARIANT 学习小记录

    一:为什么会有这个? 目前,计算机语言有很多(大哥,为什么不能就那么一样呢?),如C++.Java,此外还有JavaScript.VBScript等脚本语言,它们自立门派,各自维护自己的数据类型. C ...

  9. Delphi Variant oleVariant

    The OleVariant type exists on both the Windows and Linux platforms. The main difference between Vari ...

  10. 用户自定义结构数据与VARIANT转换 .

    用户自定义结构数据与VARIANT转换 cheungmine 将用户自定义的C结构数据存储成VARIANT类型,需要时再将VARIANT类型转为用户自定义的结构数据,有十分现实的意义,既然我们不想为这 ...

随机推荐

  1. 使用dlopen和dlsym来使用C++中的类

    http://my.oschina.net/u/1450061/blog/204608

  2. 浅析Java虚拟机结构与机制

    转载自:http://blog.hesey.net/2011/04/introduction-to-java-virtual-machine.html http://coolshell.cn/arti ...

  3. ubuntu 配置静态IP及DNS

    http://blog.csdn.net/njchenyi/article/details/8715417

  4. MySQL事物回滚

    #commit.rollback用来确保数据库有足够的剩余空间:#commi.rollback只能用于DML操作,即insert.update.delet;#rollback操作撤销上一个commit ...

  5. spring事务中隔离级别和spring的事务传播机制

    Transaction 也就是所谓的事务了,通俗理解就是一件事情.从小,父母就教育我们,做事情要有始有终,不能半途而废. 事务也是这样,不能做一般就不做了,要么做完,要 么就不做.也就是说,事务必须是 ...

  6. qt ui程序使用Linux的文件操作open、close (转)

    原文地址:qt ui程序使用Linux的文件操作open.close 作者:kjpioo 提出这个问题是因为在qt的QWidget类型的对象中,close()函数会和QWidget::close()冲 ...

  7. bzoj 4815 [Cqoi2017]小Q的表格——反演+分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 大概就是推式子的时候注意有两个边界都是 n ,考虑变成 2*... 之类的. 分块维护 ...

  8. 默认库“library”与其他库的使用冲突;使用 /NODEFAULTLIB:library

    您试图与不兼容的库链接. 重要事项 运行时库现在包含防止混合不同类型的指令.如果试图在同一个程序中使用不同类型的运行时库或使用调试和非调试版本的运行时库,则将收到此警告.例如,如果编译一个文件以使用一 ...

  9. [转]SQL Server 结构读取

    本文来自:http://www.cnblogs.com/StrangeCity/p/4352753.html -- 本文来自:http://www.cnblogs.com/StrangeCity/p/ ...

  10. css3实现气泡效果的聊天框

    因为CSS3尚未形成标准,所以现行的浏览器对于css3支持不太一致,某些特性需要加上浏览器前缀 css属性的浏览器前缀 前缀 渲染引擎 使用该引擎的浏览器 -khtml- KHTML Konquero ...