//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TVarData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: SystemVarClear
// Routine: System.VarClear
// Type: System.TVarData

// BeginCode
/*
This example shows how to use the TVarData type in typecasts
of Variant variables to access the internals of a variable.
*/
#include <memory>       //for STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Variant V;
  AnsiString mystr;
  if (TVarData(V).VType == varEmpty)
	ListBox1->Items->Add("Variants start empty.");
  VarClear(V);
  TVarData(V).VType = varString;
  mystr = "Here is my string";
  std::auto_ptr<char> MyBuffer(new char[mystr.Length() + 1]);
  StrCopy(MyBuffer.get(), mystr.c_str());
  TVarData(V).VString  = MyBuffer.get();
  mystr = PAnsiChar(TVarData(V).VString);
  ListBox1->Items->Add("This variant is now a string: " + mystr);
  VarClear(V);
  TVarData(V).VType = varInteger;
  TVarData(V).VInteger = 1234567;
  ListBox1->Items->Add("This variant is now an integer: " + IntToStr(TVarData(V).VInteger));
}
// EndCode
// EndExample: SystemVarClear
//---------------------------------------------------------------------------
