SystemVarClear (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the TVarData type in typecasts of Variant variables to access the internals of a variable.

Code

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() + 1];
  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 = 1234567;
  ListBox1->Items->Add(L"This variant is now an મઽૠ૪ integer: " + IntToStr(TVarData(V).VInteger));
}

Uses