SetTag example for C++ Builder
//---------------------------------------------------------------------------
void __fastcall TForm1::SetAndReadClick(TObject *Sender)
{
Variant myArray(OPENARRAY(int,(0,4)),varByte);
int nRet;
// initialize the array
myArray.PutElement(1,0);
myArray.PutElement(2,1);
myArray.PutElement(3,2);
myArray.PutElement(127,3);
// set a tag using one of the following:
LEADImage1->SetTag (32768, TAG_BYTE, 4, myArray);
// Write the tag
nRet = LEADImage1->WriteTag(Edit1->Text.c_str(), 1);
ReadTagClick(this);
LEADImage1->SetTag(32768, TAG_ASCII, 0, "My text string");
nRet = LEADImage1->WriteTag(Edit1->Text.c_str() , 1);
ReadTagClick(this);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadTagClick(TObject *Sender)
{
// read the tag back
LEADImage1->ReadTag(Edit1->Text.c_str(), 1, 32768);
GetAndDisplayTag(0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetAndDisplayTag(int lTag)
{
Variant myVar;
AnsiString Msg;
long i;
long count;
// This sub will get a certain tag and display it according to the tag type.
myVar = LEADImage1->GetTagData (lTag);
count = LEADImage1->GetTagCount (lTag);
Msg = "Type = " + IntToStr((LEADImage1->GetTagType (lTag)));
Msg = Msg + "\n" + "count = " + IntToStr((int)count);
if (LEADImage1->GetTagType(lTag) == TAG_ASCII)
Msg = Msg + "\n" + "Data = " + myVar;
else if ((LEADImage1->GetTagType(lTag) == TAG_RATIONAL) || (LEADImage1->GetTagType(lTag) == TAG_SRATIONAL))
for (i = 0; i <= count - 1; i++)
Msg = Msg + "\n" + "Data(" + IntToStr((int)i) + ") = " + IntToStr((int)myVar.GetElement(i * 2)) + "/" + IntToStr((int)myVar.GetElement(i * 2 + 1));
else
for (i = 0; i <= count - 1; i++)
Msg = Msg + "\n" + "Data(" + IntToStr((int)i) + ") = " + VarToStr(myVar.GetElement(i));
MessageBox(Handle,Msg.c_str(),"test",0);
}