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

#include <vcl.h>
#pragma hdrstop

#include "TFieldGetData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: TFieldGetData
// Property: DB.TField.DataSize
// Method: DB.TField.GetData
// Method: DB.TBlobField.IsBlob
// Property: DB.TField.DisplayName

// BeginCode
/*
This example requires a button, a test edit, and a populated
ClientDataSet.  Pipe the ClientDataSet through a DataSource
to a DGGrid or DBNavigator to control the current field.
Cast the data correctly according to the field type when
assigning to the test edit.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // Retrieve the "raw" data from Field1
  if (!CDS->Fields->Fields[0]->IsBlob()) // __classid(TField) GetData does not work for BLOB fields
  {
	void *MyBuffer = malloc(CDS->Fields->Fields[0]->DataSize);
	try
	{
	  if (!CDS->Fields->Fields[0]->GetData(MyBuffer))
		MessageDlg(CDS->Fields->Fields[0]->DisplayName + "is blank.", mtInformation, TMsgDlgButtons() << mbOK,0);
	  else
		// Do something with the data;
		Edit1->Text = reinterpret_cast<char *>(MyBuffer); // for a stringfield
	}
	__finally
	{
	  free(MyBuffer);
	}
  }
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  CDS->LoadFromFile("../CDS.XML");
}
// EndCode
// EndExample: TFieldGetData
//---------------------------------------------------------------------------
