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

#include <vcl.h>
#pragma hdrstop

#include "nist_demo_main_form.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{

     delete open_dialog;

}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormShow(TObject *Sender)
{

Left = (Screen->Width - Width)/2;
Top = (Screen->Height - Height)/2;

}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)
{


    open_dialog = new TOpenDialog(this);
//    TOpenDialog *open_dialog = new TOpenDialog(NULL);
    open_dialog->Filter = "NIST files|*.nist|All files|*.*|";


   //Gets full filename of the program
   GetModuleFileNameW(HInstance, program_file_path, MAXPATH);

   wchar_t *ptr;
   ptr = wcschr(program_file_path, '\0');  //Scans a string for the first occurrence of a given character

   // Extracts file path from full filename
   while(*ptr != '\\')
   {*ptr--;}
   *(ptr+1) = '\0';



   hBitmap = (HBITMAP)NULL;
   byte_array = (unsigned char*) NULL;

   // returns a handle to the DLL, otherwise NULL
   hNIST_library = LoadLibraryW(L"NIST_library64.dll");

   if (hNIST_library == NULL)
   {Application->MessageBox(L"Error: NIST_library64.dll not found", L"Error", MB_OK);}


   pRegisterNIST = (RegisterNIST) GetProcAddress(hNIST_library, "RegisterNIST");
   pCreateNewNISTFile = (CreateNewNISTFile)GetProcAddress(hNIST_library, "CreateNewNISTFile");
   pWriteNISTToFile = (WriteNISTToFile) GetProcAddress(hNIST_library, "WriteNISTToFile");
   pReadNISTByteArray = (ReadNISTByteArray) GetProcAddress(hNIST_library, "ReadNISTByteArray");
   pReadSizeOfNISTByteArray = (ReadSizeOfNISTByteArray) GetProcAddress(hNIST_library, "ReadSizeOfNISTByteArray");
   pReadNISTFromFile = (ReadNISTFromFile)GetProcAddress(hNIST_library, "ReadNISTFromFile");
   pReadNISTFromMemory = (ReadNISTFromMemory)GetProcAddress(hNIST_library, "ReadNISTFromMemory");
   pCheckIfRecordTypeExists = (CheckIfRecordTypeExists)GetProcAddress(hNIST_library, "CheckIfRecordTypeExists");
   pReadNumberOfRecords = (ReadNumberOfRecords)GetProcAddress(hNIST_library, "ReadNumberOfRecords");
   pReadIDCofRecord = (ReadIDCofRecord)GetProcAddress(hNIST_library, "ReadIDCofRecord");
   pReadRecordTxtField = (ReadRecordTxtField)GetProcAddress(hNIST_library, "ReadRecordTxtField");
   pReadSizeOfRecordTxtField = (ReadSizeOfRecordTxtField)GetProcAddress(hNIST_library, "ReadSizeOfRecordTxtField");
   pReadRecordTxtFieldName = (ReadRecordTxtFieldName)GetProcAddress(hNIST_library, "ReadRecordTxtFieldName");
   pReadSizeOfRecordTxtFieldName = (ReadSizeOfRecordTxtFieldName)GetProcAddress(hNIST_library, "ReadSizeOfRecordTxtFieldName");
   pReadRecordTxtFieldDescription = (ReadRecordTxtFieldDescription)GetProcAddress(hNIST_library, "ReadRecordTxtFieldDescription");
   pReadSizeOfRecordTxtFieldDescription = (ReadSizeOfRecordTxtFieldDescription)GetProcAddress(hNIST_library, "ReadSizeOfRecordTxtFieldDescription");
   pReadRecordExportedTxtFields = (ReadRecordExportedTxtFields)GetProcAddress(hNIST_library, "ReadRecordExportedTxtFields");
   pReadSizeOfRecordExportedTxtFields = (ReadSizeOfRecordExportedTxtFields)GetProcAddress(hNIST_library, "ReadSizeOfRecordExportedTxtFields");
   pReadRecordBinaryField = (ReadRecordBinaryField)GetProcAddress(hNIST_library, "ReadRecordBinaryField");
   pReadSizeOfRecordBinaryField = (ReadSizeOfRecordBinaryField)GetProcAddress(hNIST_library, "ReadSizeOfRecordBinaryField");
   pCreateHBITMAPfromRecordBinaryField = (CreateHBITMAPfromRecordBinaryField)GetProcAddress(hNIST_library, "CreateHBITMAPfromRecordBinaryField");
   pInsertRecordBinaryFieldFromFile = (InsertRecordBinaryFieldFromFile) GetProcAddress(hNIST_library, "InsertRecordBinaryFieldFromFile");
   pInsertRecordBinaryFieldFromMemory = (InsertRecordBinaryFieldFromMemory) GetProcAddress(hNIST_library, "InsertRecordBinaryFieldFromMemory");
   pInsertRecordTxtField = (InsertRecordTxtField) GetProcAddress(hNIST_library, "InsertRecordTxtField");
   pDeleteRecord = (DeleteRecord)GetProcAddress(hNIST_library, "DeleteRecord");





   if (pRegisterNIST == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of RegisterNIST failed", L"Error", MB_OK);}

   if (pCreateNewNISTFile == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of CreateNewNISTFile failed", L"Error", MB_OK);}

   if (pWriteNISTToFile == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of WriteNISTToFile failed", L"Error", MB_OK);}

   if (pReadNISTByteArray == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadNISTByteArray failed", L"Error", MB_OK);}

   if (pReadSizeOfNISTByteArray == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfNISTByteArray failed", L"Error", MB_OK);}

   if (pReadNISTFromFile == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadNISTFromFile failed", L"Error", MB_OK);}

   if (pReadNISTFromMemory == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadNISTFromMemory failed", L"Error", MB_OK);}

   if (pCheckIfRecordTypeExists == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of CheckIfRecordTypeExists failed", L"Error", MB_OK);}

   if (pReadNumberOfRecords == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadNumberOfRecords failed", L"Error", MB_OK);}

   if (pReadIDCofRecord == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadIDCofRecord failed", L"Error", MB_OK);}

   if (pReadRecordTxtField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadRecordTxtField failed", L"Error", MB_OK);}

   if (pReadSizeOfRecordTxtField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfRecordTxtField failed", L"Error", MB_OK);}

   if (pReadRecordTxtFieldName == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadRecordTxtFieldName failed", L"Error", MB_OK);}

   if (pReadSizeOfRecordTxtFieldName == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfRecordTxtFieldName failed", L"Error", MB_OK);}

   if (pReadRecordTxtFieldDescription == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadRecordTxtFieldDescription failed", L"Error", MB_OK);}

   if (pReadSizeOfRecordTxtFieldDescription == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfRecordTxtFieldDescription failed", L"Error", MB_OK);}

   if (pReadRecordExportedTxtFields == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadRecordExportedTxtFields failed", L"Error", MB_OK);}

   if (pReadSizeOfRecordExportedTxtFields == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfRecordExportedTxtFields failed", L"Error", MB_OK);}

   if (pReadRecordBinaryField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadRecordBinaryField failed", L"Error", MB_OK);}

   if (pReadSizeOfRecordBinaryField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of ReadSizeOfRecordBinaryField failed", L"Error", MB_OK);}

   if (pCreateHBITMAPfromRecordBinaryField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of CreateHBITMAPfromRecordBinaryField failed", L"Error", MB_OK);}

   if (pInsertRecordBinaryFieldFromFile == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of InsertRecordBinaryFieldFromFile failed", L"Error", MB_OK);}

   if (pInsertRecordBinaryFieldFromMemory == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of InsertRecordBinaryFieldFromMemory failed", L"Error", MB_OK);}

   if (pInsertRecordTxtField == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of InsertRecordTxtField failed", L"Error", MB_OK);}

   if (pDeleteRecord == NULL)
   {Application->MessageBox(L"Error: GetProcAddress of DeleteRecord failed", L"Error", MB_OK);}



}
//---------------------------------------------------------------------------

void __fastcall TMainForm::RegisterButtonClick(TObject *Sender)
{

// Registers NIST (ANSI/NIST-ITL 1-2000) library on the computer.
// Returns 1 if successful, 0 otherwise.

(pRegisterNIST)();

}
//---------------------------------------------------------------------------

void __fastcall TMainForm::CreateAndInsertButtonClick(TObject *Sender)
{


    CreateAndInsertButton->Enabled = false;
    ReadAndModifyButton->Enabled = false;
    ReadAndExportButton->Enabled = false;
    ReadSingleFieldButton->Enabled = false;
    DeleteSingleFieldButton->Enabled = false;
    RegisterButton->Enabled = false;
    Screen->Cursor = crHourGlass;


   //Creates new empty NIST file
   (pCreateNewNISTFile)();



//======================================================
    Application->MessageBox(L"Inserting/replacing Type-1 and Type-2 records...", L"NIST library", MB_OK);

   //Type-1 record Logical record length (LEN) field is handled automatically
   //and the value of the "LEN" field cannot be changed manually.
   //(pInsertType1Record)("LEN", "100");

   //You can modify value of Type-1 record Version number (VER) field, however please keep in mind that
   //the entry in "VER" field for ANSI/NIST-ITL 1-2000 approved standard must be "0300".
   //(pInsertType1Record)("VER", "0300");

   //Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
   (pInsertRecordTxtField)(1, -1, -1, "TOT", "IMG");

   //Modifies NIST file, inserts/replaces Type-1 record date (DAT)
   (pInsertRecordTxtField)(1, -1, -1, "DAT", "20081031");

   //Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
   //The length of Priority (PRY) field must be equal to 1 bytes
   (pInsertRecordTxtField)(1, -1, -1, "PRY", "1");

   //Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
   (pInsertRecordTxtField)(1, -1, -1, "DAI", "Central Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
   (pInsertRecordTxtField)(1, -1, -1, "ORI", "Local Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
   (pInsertRecordTxtField)(1, -1, -1, "TCN", "000045321");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
   (pInsertRecordTxtField)(1, -1, -1, "TCR", "0000078901");

   //Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
   //The length of Native scanning resolution(NSR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NSR", "19.69");

   //Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
   //The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NTR", "19.69");

   //Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
   (pInsertRecordTxtField)(1, -1, -1, "DOM", "NORAM");

   //Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
   //The length of Greenwich mean time (GMT) field must be equal to 15 bytes
   (pInsertRecordTxtField)(1, -1, -1, "GMT", "20081031152345Z");


   //Modifies NIST file, inserts three Type-2 records,
   //if these records already exist then they are overwritten and replaced

   //Inserts first Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "James Clerk");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Maxwell");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "Berlin, Germany");

   //Inserts second Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "John Smith");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Watson");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "London, UK");

   //Inserts third Type-2 record
   idc_current = (pInsertRecordTxtField)(2, -1, 30, "", "Alphonse Gabriel");
   (pInsertRecordTxtField)(2, idc_current, 31, "", "Al Capone");
   (pInsertRecordTxtField)(2, idc_current, 32, "", "New York, USA");




   //Sets input directory as "input" subdirectory of the program location
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");


    Application->MessageBox(L"Inserting/replacing Type-4 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts 14 Type-4 records (inserts 14 fingerprint WSQ images).
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_01.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "10");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_02.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "9");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_03.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "8");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_04.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "7");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_05.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "6");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_06.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "5");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_07.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "4");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_08.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "3");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_09.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "2");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_10.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "1");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_11.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "14");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_12.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "13");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_13.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "12");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_14.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, -1, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "11");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");





//Fields of the Type-7 logical record are user-defined.
//Individual fields required for a given transaction, such as field description,
//size, and content shall conform to the specifications set forth by the agency
//to whom the transmission is being sent.
//L"NIST library" uses Interpol Implementation of the Type-7 logical record,
//prepared by The Interpol AFIS Expert Group, version No. 4.22b – October 28, 2005
    Application->MessageBox(L"Inserting/replacing Type-7 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-7 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_01.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "25");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_02.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "26");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_03.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "21");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type7_04.jpg");
   idc_current = (pInsertRecordBinaryFieldFromFile)(7, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(7, idc_current, -1, "IMT", "1");
   (pInsertRecordTxtField)(7, idc_current, -1, "IMD", "22");
//  PCN value of "0000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "PCN", "0000000000");
//  IMR value of "00000000000" was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "IMR", "00000000000");
//  HLL value of image width was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "VLL", "0");
//  GCA value was already inserted by default when creating Type-7 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(7, idc_current, -1, "GCA", "3");



    Application->MessageBox(L"Inserting/replacing Type-8 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-8 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type8_01.bin");
   idc_current = (pInsertRecordBinaryFieldFromFile)(8, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(8, idc_current, -1, "SIG", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "SRT", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "ISR", "1");
//  HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "HLL", "1000");
//  VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "VLL", "500");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type8_02.bin");
   idc_current = (pInsertRecordBinaryFieldFromFile)(8, -1, System::UTF8Encode(String(filename)).c_str());

   (pInsertRecordTxtField)(8, idc_current, -1, "SIG", "1");
   (pInsertRecordTxtField)(8, idc_current, -1, "SRT", "0");
   (pInsertRecordTxtField)(8, idc_current, -1, "ISR", "1");
//  HLL value (image width) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "HLL", "1000");
//  VLL value (image height) needs to be set manually because input file is in uncompressed format, and cannot be determined automatically when creating Type-8 record
   (pInsertRecordTxtField)(8, idc_current, -1, "VLL", "500");





    Application->MessageBox(L"Inserting/replacing Type-10 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-10 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_01.jpg");
//   wcscat(filename, L"type10_01.png");
//   wcscat(filename, L"type10_01.jp2");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");
//   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"SCAR");


   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPEGB");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"F");  //Full Face Frontal




   filename[0] = 0;
   wcscat(filename, filedirectory);
//   wcscat(filename, L"type10_02.jpg");
   wcscat(filename, L"type10_02.png");
//   wcscat(filename, L"type10_02.jp2");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "PNG");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"R");  //Right Profile


   filename[0] = 0;
   wcscat(filename, filedirectory);
//   wcscat(filename, L"type10_03.jpg");
//   wcscat(filename, L"type10_03.png");
   wcscat(filename, L"type10_03.jp2");


   idc_current = (pInsertRecordBinaryFieldFromFile)(10, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JP2" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JP2");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"A");  //Angled Pose





    Application->MessageBox(L"Inserting/replacing Type-13 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-13 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type13_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(13, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Impression type (IMP)
   (pInsertRecordTxtField)(13, idc_current, -1, "IMP" ,"6");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(13, idc_current, -1, "SRC" ,"MDNISTVIP");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Latent capture date (LCD)
   (pInsertRecordTxtField)(13, idc_current, -1, "LCD" ,"19990707");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Scale units (SLC)
   (pInsertRecordTxtField)(13, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(13, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(13, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-13 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(13, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(13, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-13 record Finger / palm position (FGP)
   (pInsertRecordTxtField)(13, idc_current, -1, "FGP" ,"8");



    Application->MessageBox(L"Inserting/replacing Type-14 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-14 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type14_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(14, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
   (pInsertRecordTxtField)(14, idc_current, -1, "IMP" ,"3");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SRC" ,"MDNISTVIP");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
   (pInsertRecordTxtField)(14, idc_current, -1, "TCD" ,"19990707");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-14 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(14, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(14, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
   (pInsertRecordTxtField)(14, idc_current, -1, "FGP" ,"8");



    Application->MessageBox(L"Inserting/replacing Type-15 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-15 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"24");



   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_02.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"25");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type15_03.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(15, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Impression type (IMP)
   (pInsertRecordTxtField)(15, idc_current, -1, "IMP" ,"10");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Source agency/ORI (SRC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint capture date (PCD)
   (pInsertRecordTxtField)(15, idc_current, -1, "PCD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Scale units (SLC)
   (pInsertRecordTxtField)(15, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(15, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-15 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(15, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(15, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-15 record Palmprint position (PLP)
   (pInsertRecordTxtField)(15, idc_current, -1, "PLP" ,"27");



    Application->MessageBox(L"Inserting/replacing Type-16 records...", L"NIST library", MB_OK);

//Modifies NIST file, inserts Type-16 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type16_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(16, -1, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-16 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(16, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "CSP" ,"A01");





   //Sets output file name as "sample_modified.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(!DirectoryExists(filedirectory))
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_new.nist");




   //Saves NIST into the file "sample_new.nist" (in "output" subdirectory)
   //(pWriteNISTToFile)(System::UTF8Encode(String(filename)).c_str());

   //Instead function WriteNISTToFile you can use function ReadNISTByteArray and save NIST byte array manually (the code bellow)
//==========================
     byte_array = (pReadNISTByteArray)();
     size_of_byte_array = (pReadSizeOfNISTByteArray)();

	 if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox( L"Error: open file failed", L"NIST Library Error", MB_OK );}
     if((n = fwrite(byte_array, sizeof(unsigned char), size_of_byte_array, outfp)) != size_of_byte_array)
     {Application->MessageBox( L"Error: write to file failed", L"NIST Library Error", MB_OK );}
     fclose(outfp);
//==========================


    Application->MessageBox(L"New NIST file was created, modified and saved as\n\".\\output\\sample_new.nist\"\nPlease use \"NIST viewer\" to view\n\"sample_new.nist\" file.", L"NIST Library Demo", MB_OK);




    CreateAndInsertButton->Enabled = true;
    ReadAndModifyButton->Enabled = true;
    ReadAndExportButton->Enabled = true;
    ReadSingleFieldButton->Enabled = true;
    DeleteSingleFieldButton->Enabled = true;
    RegisterButton->Enabled = true;
    Screen->Cursor = crDefault;


}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ReadAndModifyButtonClick(TObject *Sender)
{


    CreateAndInsertButton->Enabled = false;
    ReadAndModifyButton->Enabled = false;
    ReadAndExportButton->Enabled = false;
    ReadSingleFieldButton->Enabled = false;
    DeleteSingleFieldButton->Enabled = false;
    RegisterButton->Enabled = false;
    Screen->Cursor = crHourGlass;


   //Sets input file name as "sample.nist" which located in "input" subdirectory
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");
   wcscat(filename, filedirectory);
   wcscat(filename, L"sample.nist");


   if(!FileExists(filename))
   {
   Application->MessageBox(L"Error: file .\\input\\sample.nist does not exist.", L"Error", MB_OK);
   return;
   }


   //Reads NIST file
   (pReadNISTFromFile)(System::UTF8Encode(String(filename)).c_str());


   //Modifies NIST file, inserts/replaces Type-1 record Type of transaction (TOT)
   (pInsertRecordTxtField)(1, -1, -1, "TOT", "WSQ");

   //Modifies NIST file, inserts/replaces Type-1 record Date (DAT)
   (pInsertRecordTxtField)(1, -1, -1, "DAT", "20080931");

   //Modifies NIST file, inserts/replaces Type-1 record Priority (PRY)
   //The length of Priority (PRY) field must be equal to 1 bytes
   (pInsertRecordTxtField)(1, -1, -1, "PRY", "2");

   //Modifies NIST file, inserts/replaces Type-1 record Destination agency identifier (DAI)
   (pInsertRecordTxtField)(1, -1, -1, "DAI", "Central Intelligence Agency");

   //Modifies NIST file, inserts/replaces Type-1 record Originating agency identifier (ORI)
   (pInsertRecordTxtField)(1, -1, -1, "ORI", "Police Station");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control number (TCN)
   (pInsertRecordTxtField)(1, -1, -1, "TCN", "000000123");

   //Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
   (pInsertRecordTxtField)(1, -1, -1, "TCR", "000000987");

   //Modifies NIST file, inserts/replaces Type-1 record Native scanning resolution(NSR)
   //The length of Native scanning resolution(NSR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NSR", "21.33");

   //Modifies NIST file, inserts/replaces Type-1 record Nominal transmitting resolution (NTR)
   //The length of Nominal transmitting resolution (NTR) field must be equal to 5 bytes
   (pInsertRecordTxtField)(1, -1, -1, "NTR", "21.33");

   //Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
   (pInsertRecordTxtField)(1, -1, -1, "DOM", "NORAM");

   //Modifies NIST file, inserts/replaces Type-1 record Greenwich mean time (GMT)
   //The length of Greenwich mean time (GMT) field must be equal to 15 bytes
   (pInsertRecordTxtField)(1, -1, -1, "GMT", "20080931170316Z");


   //Modifies NIST file, inserts two Type-2 records,
   //if these records already exist then they are overwritten and replaced
   idc = 0;
   (pInsertRecordTxtField)(2, idc, 30, "", "William Thompson");
   (pInsertRecordTxtField)(2, idc, 31, "", "Kelvin");



   //Sets input directory as "input" subdirectory of the program location
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");


//Modifies NIST file, inserts Type-4 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_left_thumb.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, 7, System::UTF8Encode(String(filename)).c_str());


   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "6");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");


   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type4_right_thumb.wsq");
   idc_current = (pInsertRecordBinaryFieldFromFile)(4, 12, System::UTF8Encode(String(filename)).c_str());
   (pInsertRecordTxtField)(4, idc_current, -1, "IMP", "3");
   (pInsertRecordTxtField)(4, idc_current, -1, "FGP1", "1");
//  FGP2 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP2", "255");
//  FGP3 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP3", "255");
//  FGP4 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP4", "255");
//  FGP5 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP5", "255");
//  FGP6 value of "255" was already inserted by default when creating Type-4 record
//   (pInsertRecordTxtField)(4, idc_current, -1, "FGP6", "255");
   (pInsertRecordTxtField)(4, idc_current, -1, "ISR", "1");
//  HLL value of image width was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "HLL", "0");
//  VLL value of image height was already inserted by default when creating Type-4 record, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "VLL", "0");
//L"NIST library" inserts GCA value "1" automatically when creating Type-4 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(4, idc_current, -1, "GCA", "1");



//Modifies NIST file, inserts Type-10 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_Charles_Luciano_frontal.jpg");


   idc_current = (pInsertRecordBinaryFieldFromFile)(10, 23, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
//   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"SCAR");


   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "JPEGB" automatically when creating Type-10 record, based on filename *.jpg extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPEGB");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"F");  //Full Face Frontal




   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type10_Charles_Luciano_profile.jpg");

   idc_current = (pInsertRecordBinaryFieldFromFile)(10, 24, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Image type (IMT)
   (pInsertRecordTxtField)(10, idc_current, -1, "IMT" ,"FACE");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Photo date (PHD)
   (pInsertRecordTxtField)(10, idc_current, -1, "PHD" ,"20091217");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Scale units (SLC)
   (pInsertRecordTxtField)(10, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "HPS" ,"300");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(10, idc_current, -1, "VPS" ,"300");

//L"NIST library" inserts CGA value "PNG" automatically when creating Type-10 record, based on filename *.jp2 extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(10, idc_current, -1, "CGA", "JPG");

   //Modifies NIST file, inserts/replaces mandatory Type-10 record Colorspace (CSP)
   (pInsertRecordTxtField)(10, idc_current, -1, "CSP" ,"RGB");
   //(pInsertRecordTxtField)(10, idc_current, 12, "", "RGB");

   //Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
   (pInsertRecordTxtField)(10, idc_current, -1, "POS" ,"R");  //Right Profile


//Modifies NIST file, inserts Type-14 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type14_replace_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(14, 27, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Impression type (IMP)
   (pInsertRecordTxtField)(14, idc_current, -1, "IMP" ,"0");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Source agency / ORI (SRC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Tenprint capture date (TCD)
   (pInsertRecordTxtField)(14, idc_current, -1, "TCD" ,"19990923");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Scale units (SLC)
   (pInsertRecordTxtField)(14, idc_current, -1, "SLC" ,"2");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (HPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "HPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (VPS)
   (pInsertRecordTxtField)(14, idc_current, -1, "VPS" ,"197");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-13 record, based on filename *.wsq extension, here you can overwrite it with new value if needed
//   (pInsertRecordTxtField)(14, idc_current, -1, "CGA" ,"WSQ20");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Bits per pixel (BPX)
   (pInsertRecordTxtField)(14, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces mandatory Type-14 record Finger position (FGP)
   (pInsertRecordTxtField)(14, idc_current, -1, "FGP" ,"14");



/*
//Modifies NIST file, inserts Type-16 records.
//If the record with specified IDC number already exists in *.nist file,
//then existing old record is overwritten and replaced

   filename[0] = 0;
   wcscat(filename, filedirectory);
   wcscat(filename, L"type16_replace_01.wsq");

   idc_current = (pInsertRecordBinaryFieldFromFile)(16, 29, System::UTF8Encode(String(filename)).c_str());

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SRC" ,"Cognaxon");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "SLC" ,"1");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "HPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "VPS" ,"500");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
//L"NIST library" inserts CGA value "WSQ20" automatically when creating Type-16 record, based on filename *.wsq extension, here you overwrite it with new value "WSQ"
   (pInsertRecordTxtField)(16, idc_current, -1, "CGA" ,"WSQ");

   //Modifies NIST file, inserts/replaces mandatory Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "BPX" ,"8");

   //Modifies NIST file, inserts/replaces Type-16 record
   (pInsertRecordTxtField)(16, idc_current, -1, "CSP" ,"A01");
*/





   //Sets output file name as "sample_modified.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(!DirectoryExists(filedirectory))
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_modified.nist");


   //Saves NIST into the file "sample_modified.nist" (in "output" subdirectory)
   (pWriteNISTToFile)(System::UTF8Encode(String(filename)).c_str());

    Application->MessageBox(L"NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_modified.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_modified.nist\" file.", L"NIST Library Demo", MB_OK);



    CreateAndInsertButton->Enabled = true;
    ReadAndModifyButton->Enabled = true;
    ReadAndExportButton->Enabled = true;
    ReadSingleFieldButton->Enabled = true;
    DeleteSingleFieldButton->Enabled = true;
    RegisterButton->Enabled = true;
    Screen->Cursor = crDefault;


}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ReadAndExportButtonClick(TObject *Sender)
{


    if (! open_dialog->Execute() )
    {
    return;
    }


    CreateAndInsertButton->Enabled = false;
    ReadAndModifyButton->Enabled = false;
    ReadAndExportButton->Enabled = false;
    ReadSingleFieldButton->Enabled = false;
    DeleteSingleFieldButton->Enabled = false;
    RegisterButton->Enabled = false;
    Screen->Cursor = crHourGlass;


   //Sets output directory (".\output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(!DirectoryExists(filedirectory))
   {
   // Create output directory
   _wmkdir(filedirectory);
   }





     // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
//    (pReadNISTFromFile)(open_dialog->FileName.c_str());


     //Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
//==========================
     handle = _wopen(open_dialog->FileName.c_str(), O_RDONLY);

     if((ret = filelength(handle)) < 0)
     {Application->MessageBox(L"Error: filelength < 0", L"Error", MB_OK);}
     size_of_byte_array = ret;

     if((infp = _wfopen(open_dialog->FileName.c_str(), L"rb")) == (FILE *)NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}

     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}

     byte_array = (unsigned char *)malloc(size_of_byte_array * sizeof(unsigned char));
     if(byte_array == (unsigned char *)NULL)
     {Application->MessageBox(L"Error: malloc for buffer failed", L"Error", MB_OK);}

     n = fread(byte_array, sizeof(unsigned char), size_of_byte_array, infp);
     if(n != size_of_byte_array)
     {Application->MessageBox(L"Error: reading file failed", L"Error", MB_OK);}

     fclose(infp);
     close(handle);



     // Loads NIST file contents from memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
     (pReadNISTFromMemory)(byte_array, size_of_byte_array);

     // Here you need to free memory resources.
     // byte_array is no longer needed after it has been read and decoded into usable format.
     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}
//==========================



if(pCheckIfRecordTypeExists(1) == 1)
{
     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(1, 0);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(1, 0);

	 // Sets filename for saving exported data of text field from Type-1 record
	 filename[0] = 0;
	 wcscat(filename, filedirectory);
	 wcscat(filename, L"type1.txt");

     // Writes exported data of text field from Type-1 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     Application->MessageBox(L"Type-1 record text field was exported to file .\\output\\type1.txt", L"NIST library", MB_OK);

}//if(pCheckIfRecordTypeExists(1) == 1)


if(pCheckIfRecordTypeExists(2) == 1)
{
     type_2_number_of_records = (pReadNumberOfRecords)(2);

     // In Type-2 record there might be up to 12 fingerprint images.
     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_2_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(2, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(2, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(2, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-2 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type2_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-2 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

	 output_message[0] = 0;
	 strcat(output_message, "Type-2 record text field was exported to file .\\output\\type2_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.");
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }



     }//for(int i = 1; i <= type_2_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(2) == 1)



if(pCheckIfRecordTypeExists(4) == 1)
{
     type_4_number_of_records = (pReadNumberOfRecords)(4);

     // In Type-4 record there might be up to 14 fingerprint images.
     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(4, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(4, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(4, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-4 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type4_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-4 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(4, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(4, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(4, idc, -1, "GCA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-4 record
     filename[0] = 0;
	 wcscpy(filename_incomplete, filedirectory);
	 wcscat(filename_incomplete, L"type4_");
	 swprintf(filename, L"%s%d", filename_incomplete, idc);

	 output_message[0] = 0;
	 strcat(output_message, "Type-4 record text field was exported to file .\\output\\type4_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-4 record binary field was exported to file .\\output\\type4_");
	 strcat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nHigh-resolution grayscale fingerprint image was extracted from Type-4 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");

	 // Writes exported data of binary field from Type-4 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
	 {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

		// Converts NIST file binary field contents into HBITMAP image.
		// Returns image in HBITMAP format if successful, returns NULL otherwise.
		hBitmap = (pCreateHBITMAPfromRecordBinaryField)(4, idc);

		if ( hBitmap )
		{
			// Take and use Handle of HBitmap directly from NIST library DLL.
			// If the NIST library is called to load or save another picture, you will lose the current image

			OutputImage->Picture->Bitmap->Handle = hBitmap;

			//Make a copy of hBitmap into OutputImage->Picture
			//OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

			OutputImage->Width = OutputImage->Picture->Bitmap->Width;
			OutputImage->Height = OutputImage->Picture->Bitmap->Height;
			Invalidate();
			Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
		}//if ( hBitmap )


     }

     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(4) == 1)


if(pCheckIfRecordTypeExists(7) == 1)
{
     type_7_number_of_records = (pReadNumberOfRecords)(7);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(7, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(7, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(7, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-7 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type7_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
	 wcscat(filename, L".txt");

	 // Writes exported data of text field from Type-7 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
	 {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

	 }

	 // Returns size of binary NIST field.
	 size = (pReadSizeOfRecordBinaryField)(7, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
	 // returns NULL otherwise.
	 nist_binary_field = (pReadRecordBinaryField)(7, idc);

	 if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(7, idc, -1, "GCA");
	 strcpy(image_compression_code, p_image_compression_code);


	 // Sets filename for saving exported data of binary field from Type-7 record
	 output_message[0] = 0;
	 strcat(output_message, "Type-7 record text field was exported to file .\\output\\type7_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-7 record binary field was exported to file .\\output\\type7_");
	 strcat(output_message, int_converted_to_string);

	 filename[0] = 0;
	 wcscpy(filename_incomplete, filedirectory);
	 wcscat(filename_incomplete, L"type7_");
	 swprintf(filename, L"%s%d", filename_incomplete, idc);

	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nUser-defined image was extracted from Type-7 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-7 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(7, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
			Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )

     }

     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(7) == 1)



if(pCheckIfRecordTypeExists(8) == 1)
{
     type_8_number_of_records = (pReadNumberOfRecords)(8);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(8, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(8, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(8, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-8 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type8_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

	 // Writes exported data of text field from Type-8 record to the file
	 if((outfp = _wfopen(filename, L"wb")) == NULL)
	 {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
	 if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
	 {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
	 fclose(outfp);

	 }

	 // Returns size of binary NIST field.
	 size = (pReadSizeOfRecordBinaryField)(8, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
	 // returns NULL otherwise.
	 nist_binary_field = (pReadRecordBinaryField)(8, idc);

	 if(nist_binary_field)
	 {
	 // Sets filename for saving exported data of binary field from Type-8 record
	 filename[0] = 0;
	 wcscpy(filename_incomplete, filedirectory);
	 wcscat(filename_incomplete, L"type8_");
	 swprintf(filename, L"%s%d", filename_incomplete, idc);
	 wcscat(filename, L".bin");

	 output_message[0] = 0;
	 strcat(output_message, "Type-8 record text field was exported to file .\\output\\type8_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-8 record binary field was exported to file .\\output\\type8_");
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".bin.");

	 strcat(output_message, "\n\nSignature image was extracted from Type-8 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");

     // Writes exported data of binary field from Type-8 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(8, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(8) == 1)



if(pCheckIfRecordTypeExists(9) == 1)
{
     type_9_number_of_records = (pReadNumberOfRecords)(9);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(9, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(9, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(9, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-9 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type9_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-9 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(9, idc);

	 // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(9, idc);

     if(nist_binary_field)
	 {
	 //p_image_compression_code = (pReadRecordTxtField)(10, idc, -1, "CGA");
	 //strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-9 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type9_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".wsq");


	 output_message[0] = 0;
	 strcat(output_message, "Type-9 record text field was exported to file .\\output\\type9_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-9 record binary field was exported to file .\\output\\type9_");
	 strcat(output_message, int_converted_to_string);
     strcat(output_message, ".wsq.");


//	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
//	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
//	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
//	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
//	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
//	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
//	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
//	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
//	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
//	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nMinutiae data was extracted from Type-9 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");



     // Writes exported data of binary field from Type-9 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(9, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)




if(pCheckIfRecordTypeExists(10) == 1)
{
     type_10_number_of_records = (pReadNumberOfRecords)(10);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(10, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(10, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(10, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-10 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type10_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-10 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(10, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(10, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(10, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-10 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type10_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);


	 output_message[0] = 0;
	 strcat(output_message, "Type-10 record text field was exported to file .\\output\\type10_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-10 record binary field was exported to file .\\output\\type10_");
	 strcat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nFacial & SMT image was extracted from Type-10 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");



     // Writes exported data of binary field from Type-10 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(10, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(10) == 1)




if(pCheckIfRecordTypeExists(13) == 1)
{
     type_13_number_of_records = (pReadNumberOfRecords)(13);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(13, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(13, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(13, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-13 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type13_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-13 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(13, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(13, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(13, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-13 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type13_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);

	 output_message[0] = 0;
	 strcat(output_message, "Type-13 record text field was exported to file .\\output\\type13_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-13 record binary field was exported to file .\\output\\type13_");
	 strcat(output_message, int_converted_to_string);

	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nVariable-resolution latent image was extracted from Type-13 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-13 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(13, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)



if(pCheckIfRecordTypeExists(14) == 1)
{
     type_14_number_of_records = (pReadNumberOfRecords)(14);


     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(14, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(14, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(14, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-14 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type14_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-14 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(14, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(14, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(14, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-14 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type14_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);


	 output_message[0] = 0;
	 strcat(output_message, "Type-14 record text field was exported to file .\\output\\type14_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-14 record binary field was exported to file .\\output\\type14_");
	 strcat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nVariable-resolution fingerprint image was extracted from Type-14 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-14 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(14, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)


if(pCheckIfRecordTypeExists(15) == 1)
{
     type_15_number_of_records = (pReadNumberOfRecords)(15);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(15, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(15, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(15, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-15 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type15_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-15 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(15, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(15, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(15, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-15 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type15_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);


	 output_message[0] = 0;
	 strcat(output_message, "Type-15 record text field was exported to file .\\output\\type15_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-15 record binary field was exported to file .\\output\\type15_");
	 strcat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nVariable-resolution palmprint image was extracted from Type-15 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-15 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(15, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)


if(pCheckIfRecordTypeExists(16) == 1)
{
     type_16_number_of_records = (pReadNumberOfRecords)(16);

     // Reads NIST file and exports all images to separate files.
     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(16, i);

     // Returns size of text NIST field.
     size = (pReadSizeOfRecordExportedTxtFields)(16, idc);

     // Returns contents of NIST file data field as text string (char array).
     nist_txt_field = (pReadRecordExportedTxtFields)(16, idc);

     if(size !=0 )
     {

     // Sets filename for saving exported data of text field from Type-16 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type16_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);
     wcscat(filename, L".txt");

     // Writes exported data of text field from Type-16 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_txt_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

     }

     // Returns size of binary NIST field.
     size = (pReadSizeOfRecordBinaryField)(16, idc);

     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     nist_binary_field = (pReadRecordBinaryField)(16, idc);

     if(nist_binary_field)
	 {
	 p_image_compression_code = (pReadRecordTxtField)(16, idc, -1, "CGA");
	 strcpy(image_compression_code, p_image_compression_code);

     // Sets filename for saving exported data of binary field from Type-16 record
     filename[0] = 0;
     wcscpy(filename_incomplete, filedirectory);
     wcscat(filename_incomplete, L"type16_");
     swprintf(filename, L"%s%d", filename_incomplete, idc);


	 output_message[0] = 0;
	 strcat(output_message, "Type-16 record text field was exported to file .\\output\\type16_");
	 itoa(idc, int_converted_to_string, 10);
	 strcat(output_message, int_converted_to_string);
	 strcat(output_message, ".txt.\n\nType-16 record binary field was exported to file .\\output\\type16_");
	 strcat(output_message, int_converted_to_string);


	 if((strcmp(image_compression_code, "0") == 0) | (strcmp(image_compression_code, "NONE") == 0))
	 {wcscat(filename, L".bin"); strcat(output_message, ".bin.");}
	 else if((strcmp(image_compression_code, "1") == 0) | (strcmp(image_compression_code, "WSQ20") == 0) | (strcmp(image_compression_code, "WSQ") == 0))
	 {wcscat(filename, L".wsq"); strcat(output_message, ".wsq.");}
	 else if((strcmp(image_compression_code, "2") == 0) | (strcmp(image_compression_code, "JPEGB") == 0) | (strcmp(image_compression_code, "3") == 0) | (strcmp(image_compression_code, "JPEGL") == 0))
	 {wcscat(filename, L".jpg"); strcat(output_message, ".jpg.");}
	 else if((strcmp(image_compression_code, "4") == 0) | (strcmp(image_compression_code, "JP2") == 0) | (strcmp(image_compression_code, "5") == 0) | (strcmp(image_compression_code, "JP2L") == 0))
	 {wcscat(filename, L".jp2"); strcat(output_message, ".jp2.");}
	 else if((strcmp(image_compression_code, "6") == 0) | (strcmp(image_compression_code, "PNG") == 0))
	 {wcscat(filename, L".png"); strcat(output_message, ".png.");}

	 strcat(output_message, "\n\nVariable-resolution user-defined testing image was extracted from Type-16 record\nbinary field of NIST file and converted into HBITMAP for showing on form.");


     // Writes exported data of binary field from Type-16 record to the file
     if((outfp = _wfopen(filename, L"wb")) == NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}
     if((n = fwrite(nist_binary_field, 1, size, outfp)) != size)
     {Application->MessageBox(L"Error: write to file failed", L"Error", MB_OK);}
     fclose(outfp);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.
        hBitmap = (pCreateHBITMAPfromRecordBinaryField)(16, idc);

        if ( hBitmap )
        {
            // Take and use Handle of HBitmap directly from NIST library DLL.
            // If the NIST library is called to load or save another picture, you will lose the current image

            OutputImage->Picture->Bitmap->Handle = hBitmap;

            //Make a copy of hBitmap into OutputImage->Picture
            //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

            OutputImage->Width = OutputImage->Picture->Bitmap->Width;
            OutputImage->Height = OutputImage->Picture->Bitmap->Height;
            Invalidate();
            Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
        }//if ( hBitmap )



     }

     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)








    CreateAndInsertButton->Enabled = true;
    ReadAndModifyButton->Enabled = true;
    ReadAndExportButton->Enabled = true;
    ReadSingleFieldButton->Enabled = true;
    DeleteSingleFieldButton->Enabled = true;
    RegisterButton->Enabled = true;
    Screen->Cursor = crDefault;


}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ReadSingleFieldButtonClick(TObject *Sender)
{


    if (! open_dialog->Execute() )
    {
    return;
    }


    CreateAndInsertButton->Enabled = false;
    ReadAndModifyButton->Enabled = false;
    ReadAndExportButton->Enabled = false;
    ReadSingleFieldButton->Enabled = false;
    DeleteSingleFieldButton->Enabled = false;
    RegisterButton->Enabled = false;
    Screen->Cursor = crHourGlass;


     // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
//    (pReadNISTFromFile)(open_dialog->FileName.c_str());


     //Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
//==========================
     handle = _wopen(open_dialog->FileName.c_str(), O_RDONLY);

     if((ret = filelength(handle)) < 0)
     {Application->MessageBox(L"Error: filelength < 0", L"Error", MB_OK);}
     size_of_byte_array = ret;

	 if((infp = _wfopen(open_dialog->FileName.c_str(), L"rb")) == (FILE *)NULL)
     {Application->MessageBox(L"Error: open file failed", L"Error", MB_OK);}

     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}

     byte_array = (unsigned char *)malloc(size_of_byte_array * sizeof(unsigned char));
     if(byte_array == (unsigned char *)NULL)
     {Application->MessageBox(L"Error: malloc for buffer failed", L"Error", MB_OK);}

     n = fread(byte_array, sizeof(unsigned char), size_of_byte_array, infp);
     if(n != size_of_byte_array)
     {Application->MessageBox(L"Error: reading file failed", L"Error", MB_OK);}

     fclose(infp);
     close(handle);



     // Loads NIST file contents from memory and decodes NIST file data into
     // usable format. This function must be called at the beginning (one time only) before
     // any further processing of NIST file.
     (pReadNISTFromMemory)(byte_array, size_of_byte_array);

     // Here you need to free memory resources.
     // byte_array is no longer needed after it has been read and decoded into usable format.
     if(byte_array != (unsigned char*) NULL)
     {free(byte_array); byte_array = (unsigned char*) NULL;}
//==========================


if(pCheckIfRecordTypeExists(1) == 1)
{

     output_message[0] = 0;

     strcat(output_message, "Type-1 record field values were read in cycle using field number\n\n");

     for(int i = 1; i < 16; i++)
     {
     strcat(output_message, "Type-1 record ");
     //Reads Type-1 record i Field Description
     nist_txt_field = (pReadRecordTxtFieldDescription)(1, -1, i, "");
     strcat(output_message, nist_txt_field);
     strcat(output_message, " (");
     //Reads Type-1 record i Field Name
     nist_txt_field = (pReadRecordTxtFieldName)(1, -1, i);
     strcat(output_message, nist_txt_field);
     strcat(output_message, ") = ");
     //Reads Type-1 record i Field Value
     nist_txt_field = (pReadRecordTxtField)(1, -1, i, "");
     strcat(output_message, nist_txt_field);
     strcat(output_message, "\n");
     }
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     output_message[0] = 0;

     strcat(output_message, "Type-1 record field values were read using field names\n\n");

     //Reads Type-1 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "LEN");
     strcat(output_message, "Type-1 record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Version number (VER) of the standard implemented by the software or system creating the file
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "VER");
     strcat(output_message, "\nType-1 record Version number (VER) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record File content (CNT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "CNT");
     strcat(output_message, "\nType-1 record File content (CNT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Type of transaction (TOT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TOT");
     strcat(output_message, "\nType-1 record Type of transaction (TOT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Date (DAT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DAT");
     strcat(output_message, "\nType-1 record Date (DAT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Priority (PRY)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "PRY");
     strcat(output_message, "\nType-1 record Priority (PRY) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Destination agency identifier (DAI)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DAI");
     strcat(output_message, "\nType-1 record Destination agency identifier (DAI) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Originating agency identifier (ORI)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "ORI");
     strcat(output_message, "\nType-1 record Originating agency identifier (ORI) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Transaction control number (TCN)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TCN");
     strcat(output_message, "\nType-1 record Transaction control number (TCN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Transaction control reference (TCR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "TCR");
     strcat(output_message, "\nType-1 record Transaction control reference (TCR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Native scanning resolution(NSR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "NSR");
     strcat(output_message, "\nType-1 record Native scanning resolution (NSR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Nominal transmitting resolution (NTR)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "NTR");
     strcat(output_message, "\nType-1 record Nominal transmitting resolution (NTR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Domain name (DOM)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DOM");
     strcat(output_message, "\nType-1 record Domain name (DOM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Greenwich mean time (GMT)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "GMT");
     strcat(output_message, "\nType-1 record Greenwich mean time (GMT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-1 record Directory of character sets (DCS)
     nist_txt_field = (pReadRecordTxtField)(1, -1, -1, "DCS");
     strcat(output_message, "\nType-1 record Directory of character sets (DCS) = ");
     strcat(output_message, nist_txt_field);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


}//if(CheckIfRecordTypeExists(1) == 1)



if(pCheckIfRecordTypeExists(2) == 1)
{

     type_2_number_of_records = (pReadNumberOfRecords)(2);
     printf(output_message, "%s%d", "Type-2 number of records = ", type_2_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     for(int i = 1; i <= type_2_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(2, i);


     //Reads Type-2 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(2, idc, 1 , "");
     strcat(output_message, "Type-2 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);


     //Reads Type-2 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(2, idc, 2, "");
     strcat(output_message, "\nType-2 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-2 record User-defined field #30
     nist_txt_field = (pReadRecordTxtField)(2, idc, 30, "");
     strcat(output_message, "\nType-2 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") Type-2 record User-defined field #30 = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-2 record User-defined field #31
     nist_txt_field = (pReadRecordTxtField)(2, idc, 31, "");
     strcat(output_message, "\nType-2 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") Type-2 record User-defined field #31 = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-2 record User-defined field #32
     nist_txt_field = (pReadRecordTxtField)(2, idc, 32, "");
     strcat(output_message, "\nType-2 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") Type-2 record User-defined field #32 = ");
     strcat(output_message, nist_txt_field);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);

     }//for(int i = 1; i <= type_2_number_of_records; i++)


}//if(CheckIfRecordTypeExists(2) == 1)




if(pCheckIfRecordTypeExists(4) == 1)
{

     type_4_number_of_records = (pReadNumberOfRecords)(4);
     printf(output_message, "%s%d", "Type-4 number of records = ", type_4_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // In Type-4 record there might be up to 14 fingerprint images.
     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(4, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-4 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "LEN");
//     nist_txt_field = (pReadRecordTxtField)(4, idc, 1, "");
     strcat(output_message, "Type-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "IDC");
//     nist_txt_field = (pReadRecordTxtField)(4, idc, 2, "");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "IMP");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Impression type (IMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Finger position (FGP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Known or most probable Finger position (FGP1)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP1");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Known or most probable Finger position (FGP1) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Second possible Finger position (FGP2)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP2");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Second possible Finger position (FGP2) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Third possible Finger position (FGP3)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP3");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Third possible Finger position (FGP3) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Fourth possible Finger position (FGP4)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP4");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Fourth possible Finger position (FGP4) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Fifth possible Finger position (FGP5)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP5");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Fifth possible Finger position (FGP5) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Sixth possible Finger position (FGP6)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "FGP6");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Sixth possible Finger position (FGP6) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Image scanning resolution (ISR)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "ISR");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image scanning resolution (ISR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "HLL");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "VLL");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-4 record Grayscale compression algorithm (GCA)
     nist_txt_field = (pReadRecordTxtField)(4, idc, -1, "GCA");
     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Grayscale compression algorithm (GCA) = ");
     strcat(output_message, nist_txt_field);


     // Returns Type-4 record Size of binary field.
     size = (pReadSizeOfRecordBinaryField)(4, idc);

     strcat(output_message, "\nType-4 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Size of binary field = ");
     itoa(size, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);


     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     //nist_binary_field = (pReadType4RecordBinaryField)(1, idc);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(4, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nHigh-resolution grayscale fingerprint image was extracted from Type-4 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )




     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(CheckIfRecordTypeExists(4) == 1)


if(pCheckIfRecordTypeExists(7) == 1)
{

     type_7_number_of_records = (pReadNumberOfRecords)(7);
     printf(output_message, "%s%d", "Type-7 number of records = ", type_7_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // In Type-7 record there might be up to 17 fingerprint images.
     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(7, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-7 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "LEN");
     strcat(output_message, "Type-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IDC");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Image type (IMT)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMT");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image type (IMT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Image description (IMD)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMD");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image description (IMD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Pattern classification (PCN)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "PCN");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Pattern classification (PCN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Image capture resolution (IMR)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "IMR");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image capture resolution (IMR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "HLL");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Horizontal line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "VLL");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-7 record Gray-scale compression algorithm (GCA)
     nist_txt_field = (pReadRecordTxtField)(7, idc, -1, "GCA");
     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Gray-scale compression algorithm (GCA) = ");
     strcat(output_message, nist_txt_field);



     // Returns Type-7 record Size of binary field.
     size = (pReadSizeOfRecordBinaryField)(7, idc);

     strcat(output_message, "\nType-7 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Size of binary field = ");
     itoa(size, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);


     // Returns contents of NIST file binary field as byte array if successful,
     // returns NULL otherwise.
     //nist_binary_field = (pReadType7RecordBinaryField)(1, idc);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(7, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nUser-defined image was extracted from Type-7 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )




     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(CheckIfRecordTypeExists(7) == 1)



if(pCheckIfRecordTypeExists(8) == 1)
{
     type_8_number_of_records = (pReadNumberOfRecords)(8);
     printf(output_message, "%s%d", "Type-8 number of records = ", type_8_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Reads NIST file and shows facial and SMT images on the screen.
     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(8, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-8 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "LEN");
     strcat(output_message, "Type-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "IDC");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Signature type (SIG)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "SIG");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Signature type (SIG) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Signature representation type (SRT)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "SRT");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Signature representation type (SRT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Image scanning resolution (ISR)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "ISR");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image scanning resolution (ISR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "HLL");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-8 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(8, idc, -1, "VLL");
     strcat(output_message, "\nType-8 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(8, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nSignature image was extracted from Type-8 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )

     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(CheckIfRecordTypeExists(8) == 1)


if(pCheckIfRecordTypeExists(9) == 1)
{

     type_9_number_of_records = (pReadNumberOfRecords)(9);
     printf(output_message, "%s%d", "Type-9 number of records = ", type_9_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Reads NIST file and shows minutiae data images on the screen.
     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(9, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-9 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "LEN");
     strcat(output_message, "Type-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "IDC");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "IMP");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Impression type (IMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Minutiae format (FMT)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FMT");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Minutiae format (FMT) = ");
     strcat(output_message, nist_txt_field);

     if(strcmp(nist_txt_field, "S") == 0)
     {

     //Reads Type-9 record Originating fingerprint reading system (OFR)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "OFR");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Originating fingerprint reading system (OFR) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FGP");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Finger position (FGP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Fingerprint pattern classification (FPC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "FPC");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Fingerprint pattern classification (FPC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Core position (CRP)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "CRP");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Core position (CRP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Delta(s) position (DLT)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "DLT");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Delta(s) position (DLT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Number of minutiae (MIN)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "MIN");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Number of minutiae (MIN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Number of minutiae (RDG)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "RDG");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Minutiae ridge count indicator (RDG) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-9 record Number of minutiae (MRC)
     nist_txt_field = (pReadRecordTxtField)(9, idc, -1, "MRC");
     strcat(output_message, "\nType-9 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Minutiae and ridge count data (MRC) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);

     }//if(strcmp(nist_txt_field, "S") == 0)


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(9, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


//         strcat(output_message, "\nMinutiae data was extracted from Type-9 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
//         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )
     else
     {

         strcat(output_message, "\nMinutiae data was extracted from Type-9 record binary field\nof NIST file.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }


     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)



if(pCheckIfRecordTypeExists(10) == 1)
{
     type_10_number_of_records = (pReadNumberOfRecords)(10);
     printf(output_message, "%s%d", "Type-10 number of records = ", type_10_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Reads NIST file and shows facial and SMT images on the screen.
     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(10, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-10 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "LEN");
     strcat(output_message, "Type-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "IDC");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Image type (IMT)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "IMT");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image type (IMT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SRC");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Source agency / ORI (SRC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Photo date (PHD)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PHD");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Photo date (PHD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "HLL");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "VLL");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SLC");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scale units (SLC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "HPS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal pixel scale (HPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "VPS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical pixel scale (VPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "CGA");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Compression algorithm (CGA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Colorspace (CSP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "CSP");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Colorspace (CSP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject acquisition profile (SAP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SAP");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject acquisition profile (SAP) = ");
     strcat(output_message, nist_txt_field);


     //Reads Type-10 record Subject pose (POS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "POS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject pose (POS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Pose offset angle (POA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "POA");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Pose offset angle (POA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Photo description (PXS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PXS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Photo description (PXS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Photo acquisition source (PAS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "PAS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Photo acquisition source (PAS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject quality score (SQS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SQS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject quality score (SQS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject pose angles (SPA)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SPA");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject pose angles (SPA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject facial description (SXS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SXS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject facial description (SXS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject eye color (SEC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SEC");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject eye color (SEC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Subject hair color (SHC)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SHC");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Subject hair color (SHC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Facial feature points (FFP)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "FFP");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Facial feature points (FFP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "DMM");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Device monitoring mode (DMM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record NCIC designation code (SMT)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMT");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record NCIC designation code (SMT) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record SMT size (SMS)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMS");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record SMT size (SMS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record SMT descriptors (SMD)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "SMD");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record SMT descriptors (SMD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-10 record Color (COL)
     nist_txt_field = (pReadRecordTxtField)(10, idc, -1, "COL");
     strcat(output_message, "\nType-10 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Color (COL) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(10, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nFacial & SMT image was extracted from Type-10 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )

     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(CheckIfRecordTypeExists(10) == 1)



if(pCheckIfRecordTypeExists(13) == 1)
{
     type_13_number_of_records = (pReadNumberOfRecords)(13);
     printf(output_message, "%s%d", "Type-13 number of records = ", type_13_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);

     // Reads NIST file and shows latent images on the screen.
     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(13, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-13 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "LEN");
     strcat(output_message, "Type-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Image Designation Character (IDC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "IDC");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Impression Type (IMP)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "IMP");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (IMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SRC");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Source agency / ORI (SRC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Latent capture date (LCD)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "LCD");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Latent capture date (LCD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Latent capture date (HLL)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "HLL");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Latent capture date (VLL)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "VLL");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SLC");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scale units (SLC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "HPS");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal pixel scale (HPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "VPS");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical pixel scale (VPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "CGA");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Compression algorithm (CGA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "BPX");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Bits per pixel (BPX) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Finger / palm position (FGP)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "FGP");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Finger / palm position (FGP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Search position descriptors (SPD)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SPD");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Search position descriptors (SPD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Print position coordinates (PPC)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "PPC");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Print position coordinates (PPC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SHPS");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned horizontal pixel scale (SHPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "SVPS");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned vertical pixel scale (SVPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-13 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(13, idc, -1, "COM");
     strcat(output_message, "\nType-13 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Comment (COM) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(13, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nVariable-resolution latent image was extracted from Type-13 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )

     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)


if(pCheckIfRecordTypeExists(14) == 1)
{
     type_14_number_of_records = (pReadNumberOfRecords)(14);
     printf(output_message, "%s%d", "Type-14 number of records = ", type_14_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Reads NIST file and shows tenprint images images on the screen.
     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(14, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-14 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "LEN");
     strcat(output_message, "Type-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "IDC");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "IMP");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Impression type (IMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Source agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SRC");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Source agency / ORI (SRC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Tenprint capture date (TCD)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "TCD");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Tenprint capture date (TCD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "HLL");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "VLL");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SLC");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scale units (SLC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "HPS");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal pixel scale (HPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "VPS");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical pixel scale (VPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "CGA");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Compression algorithm (CGA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "BPX");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Bits per pixel (BPX) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Finger position (FGP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "FGP");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Finger position (FGP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Print position descriptors (PPD)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "PPD");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Print position descriptors (PPD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Print position coordinates (PPC)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "PPC");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Print position coordinates (PPC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SHPS");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned horizontal pixel scale (SHPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SVPS");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned vertical pixel scale (SVPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Amputated or bandaged (AMP)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "AMP");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Amputated or bandaged (AMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "COM");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Comment (COM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Finger segment position(s) (SEG)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SEG");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Finger segment position(s) (SEG) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record NIST quality metric (NQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "NQM");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record NIST quality metric (NQM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Segmentation quality metric (SQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "SQM");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Segmentation quality metric (SQM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Fingerprint quality metric (FQM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "FQM");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Fingerprint quality metric (FQM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Alternate finger segment position(s) (ASEG)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "ASEG");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Alternate finger segment position(s) (ASEG) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-14 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(14, idc, -1, "DMM");
     strcat(output_message, "\nType-14 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Device monitoring mode (DMM) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(14, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nVariable-resolution fingerprint image was extracted from Type-14 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )


     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)



if(pCheckIfRecordTypeExists(15) == 1)
{
     type_15_number_of_records = (pReadNumberOfRecords)(15);
     printf(output_message, "%s%d", "Type-15 number of records = ", type_15_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);

     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(15, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-15 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "LEN");
     strcat(output_message, "Type-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "IDC");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Impression type (IMP)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "IMP");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Impression type (IMP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Source agency/ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SRC");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Source agency/ORI (SRC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Palmprint capture date (PCD)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PCD");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Palmprint capture date (PCD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Horizontal line length (HLL)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "HLL");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal line length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Vertical line length (VLL)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "VLL");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical line length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Scale units (SLC)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SLC");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scale units (SLC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Horizontal pixel scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "HPS");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal pixel scale (HPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Vertical pixel scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "VPS");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical pixel scale (VPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Compression algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "CGA");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Compression algorithm (CGA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Bits per pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "BPX");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Bits per pixel (BPX) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Palmprint position (PLP)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PLP");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Palmprint position (PLP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Scanned horizontal pixel scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SHPS");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned horizontal pixel scale (SHPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Scanned vertical pixel scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "SVPS");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned vertical pixel scale (SVPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "COM");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Comment (COM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Palmprint quality metric (PQM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "PQM");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Palmprint quality metric (PQM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-15 record Device monitoring mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(15, idc, -1, "DMM");
     strcat(output_message, "\nType-15 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Device monitoring mode (DMM) = ");
     strcat(output_message, nist_txt_field);
//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(15, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


         strcat(output_message, "\nVariable-resolution palmprint image was extracted from Type-15 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )


     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)


if(pCheckIfRecordTypeExists(16) == 1)
{
     type_16_number_of_records = (pReadNumberOfRecords)(16);
     printf(output_message, "%s%d", "Type-16 number of records = ", type_16_number_of_records);
     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);

     // Reads NIST file and shows fingerprint images on the screen.
     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     output_message[0] = 0;

     idc = (pReadIDCofRecord)(16, i);

     // Returns contents of NIST file data field as text string (char array).

     //Reads Type-16 record Logical record length (LEN)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "LEN");
     strcat(output_message, "Type-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Logical record length (LEN) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Image designation character (IDC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "IDC");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Image designation character (IDC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record User-Defined Image (UDI)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UDI");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record User-Defined Image (UDI) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Source Agency / ORI (SRC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SRC");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Source Agency / ORI (SRC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record User-Defined Testing Date (UTD)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UTD");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record User-Defined Testing Date (UTD) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Horizontal Line Length (HLL)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "HLL");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal Line Length (HLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Vertical Line Length (VLL)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "VLL");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical Line Length (VLL) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Scale Units (SLC)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SLC");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scale Units (SLC) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Horizontal Pixel Scale (HPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "HPS");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Horizontal Pixel Scale (HPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Vertical Pixel Scale (VPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "VPS");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Vertical Pixel Scale (VPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Compression Algorithm (CGA)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "CGA");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Compression Algorithm (CGA) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Bits Per Pixel (BPX)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "BPX");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Bits Per Pixel (BPX) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Color Space (CSP)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "CSP");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Color Space (CSP) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Scanned Horizontal Pixel Scale (SHPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SHPS");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned Horizontal Pixel Scale (SHPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Scanned Vertical Pixel Scale (SVPS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "SVPS");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Scanned Vertical Pixel Scale (SVPS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Comment (COM)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "COM");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Comment (COM) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record User-Defined Testing Image Quality Score (UQS)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "UQS");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record User-Defined Testing Image Quality Score (UQS) = ");
     strcat(output_message, nist_txt_field);

     //Reads Type-16 record Device Monitoring Mode (DMM)
     nist_txt_field = (pReadRecordTxtField)(16, idc, -1, "DMM");
     strcat(output_message, "\nType-16 (");
     itoa(idc, int_converted_to_string, 10);
     strcat(output_message, int_converted_to_string);
     strcat(output_message, ") record Device Monitoring Mode (DMM) = ");
     strcat(output_message, nist_txt_field);


//     Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);


     // Converts NIST file binary field contents into HBITMAP image.
     // Returns image in HBITMAP format if successful, returns NULL otherwise.
     hBitmap = (pCreateHBITMAPfromRecordBinaryField)(16, idc);

     if ( hBitmap )
     {
         // Take and use Handle of HBitmap directly from NIST library DLL.
         // If the NIST library is called to load or save another picture, you will lose the current image

         OutputImage->Picture->Bitmap->Handle = hBitmap;

         //Make a copy of hBitmap into OutputImage->Picture
         //OutputImage->Picture->Bitmap->Handle  = (HBITMAP)CopyImage((HANDLE)hBitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG);

         OutputImage->Width = OutputImage->Picture->Bitmap->Width;
         OutputImage->Height = OutputImage->Picture->Bitmap->Height;
         Invalidate();


		 strcat(output_message, "\nVariable-resolution user-defined testing image was extracted from Type-16 record binary field\nof NIST file and converted into HBITMAP for showing on form.");
         Application->MessageBox(String(output_message).w_str(), L"NIST library", MB_OK);
     }//if ( hBitmap )


     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)




    CreateAndInsertButton->Enabled = true;
    ReadAndModifyButton->Enabled = true;
    ReadAndExportButton->Enabled = true;
    ReadSingleFieldButton->Enabled = true;
    DeleteSingleFieldButton->Enabled = true;
    RegisterButton->Enabled = true;
    Screen->Cursor = crDefault;



}
//---------------------------------------------------------------------------

void __fastcall TMainForm::DeleteSingleFieldButtonClick(TObject *Sender)
{



    CreateAndInsertButton->Enabled = false;
    ReadAndModifyButton->Enabled = false;
    ReadAndExportButton->Enabled = false;
    ReadSingleFieldButton->Enabled = false;
    DeleteSingleFieldButton->Enabled = false;
    RegisterButton->Enabled = false;
    Screen->Cursor = crHourGlass;



   //Sets input file name as "sample.nist" which located in "input" subdirectory
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"input\\");
   wcscat(filename, filedirectory);
   wcscat(filename, L"sample.nist");



   if(!FileExists(filename))
   {
   Application->MessageBox(L"Error: file .\\input\\sample.nist does not exist.", L"Error", MB_OK);
   return;
   }


   // Reads NIST file, loads NIST file contents into memory and decodes NIST file data into
   // usable format. This function must be called at the beginning (one time only) before
   // any further processing of NIST file.
   (pReadNISTFromFile)(System::UTF8Encode(String(filename)).c_str());





if(pCheckIfRecordTypeExists(2) == 1)
{
(pDeleteRecord)(2, 0);
}


if(pCheckIfRecordTypeExists(4) == 1)
{

   //Modifies NIST file, Deletes all Type-4 records
    type_4_number_of_records = (pReadNumberOfRecords)(4);

     for(int i = 1; i <= type_4_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(4, 1); //selects the first Type-4 record
//     idc = (pReadIDCofRecord)(4, (type_4_number_of_records - i + 1)); //selects the last Type-4 record
     (pDeleteRecord)(4, idc);
     }//for(int i = 1; i <= type_4_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(4) == 1)





if(pCheckIfRecordTypeExists(7) == 1)
{

   //Modifies NIST file, Deletes all Type-7 records
    type_7_number_of_records = (pReadNumberOfRecords)(7);

     for(int i = 1; i <= type_7_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(7, 1); //selects the first Type-7 record
//     idc = (pReadIDCofRecord)(7, (type_7_number_of_records - i + 1)); //selects the last Type-7 record
     (pDeleteRecord)(7, idc);
     }//for(int i = 1; i <= type_7_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(7) == 1)




if(pCheckIfRecordTypeExists(8) == 1)
{

   //Modifies NIST file, Deletes all Type-8 records
    type_8_number_of_records = (pReadNumberOfRecords)(8);

     for(int i = 1; i <= type_8_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(8, 1); //selects the first Type-8 record
//     idc = (pReadIDCofRecord)(8, (type_8_number_of_records - i + 1)); //selects the last Type-8 record
     (pDeleteRecord)(8, idc);
     }//for(int i = 1; i <= type_8_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(8) == 1)




if(pCheckIfRecordTypeExists(9) == 1)
{

   //Modifies NIST file, Deletes all Type-9 records
    type_9_number_of_records = (pReadNumberOfRecords)(9);

     for(int i = 1; i <= type_9_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(9, 1); //selects the first Type-9 record
//     ShowMessage(idc);
//     idc = (pReadIDCofRecord)(9, (type_9_number_of_records - i + 1)); //selects the last Type-9 record
     (pDeleteRecord)(9, idc);
     }//for(int i = 1; i <= type_9_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(9) == 1)




if(pCheckIfRecordTypeExists(10) == 1)
{

   //Modifies NIST file, Deletes all Type-10 records
    type_10_number_of_records = (pReadNumberOfRecords)(10);

     for(int i = 1; i <= type_10_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(10, 1); //selects the first Type-10 record
//     idc = (pReadIDCofRecord)(10, (type_10_number_of_records - i + 1)); //selects the last Type-10 record
     (pDeleteRecord)(10, idc);
     }//for(int i = 1; i <= type_10_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(10) == 1)



if(pCheckIfRecordTypeExists(13) == 1)
{

   //Modifies NIST file, Deletes all Type-13 records
    type_13_number_of_records = (pReadNumberOfRecords)(13);

     for(int i = 1; i <= type_13_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(13, 1); //selects the first Type-13 record
//     idc = (pReadIDCofRecord)(13, (type_13_number_of_records - i + 1)); //selects the last Type-13 record
     (pDeleteRecord)(13, idc);
     }//for(int i = 1; i <= type_13_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(13) == 1)



if(pCheckIfRecordTypeExists(14) == 1)
{

   //Modifies NIST file, Deletes all Type-14 records
    type_14_number_of_records = (pReadNumberOfRecords)(14);


     for(int i = 1; i <= type_14_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(14, 1); //selects the first Type-14 record
//     idc = (pReadIDCofRecord)(14, (type_14_number_of_records - i + 1)); //selects the last Type-14 record
     (pDeleteRecord)(14, idc);
     }//for(int i = 1; i <= type_14_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(14) == 1)




if(pCheckIfRecordTypeExists(15) == 1)
{
   //Modifies NIST file, Deletes all Type-15 records
    type_15_number_of_records = (pReadNumberOfRecords)(15);

     for(int i = 1; i <= type_15_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(15, 1); //selects the first Type-15 record
//     idc = (pReadIDCofRecord)(15, (type_15_number_of_records - i + 1)); //selects the last Type-15 record
     (pDeleteRecord)(15, idc);
     }//for(int i = 1; i <= type_15_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(15) == 1)





if(pCheckIfRecordTypeExists(16) == 1)
{
   //Modifies NIST file, Deletes all Type-16 records
    type_16_number_of_records = (pReadNumberOfRecords)(16);

     for(int i = 1; i <= type_16_number_of_records; i++)
     {
     idc = (pReadIDCofRecord)(16, 1); //selects the first Type-16 record
//     idc = (pReadIDCofRecord)(16, (type_16_number_of_records - i + 1)); //selects the last Type-16 record
     (pDeleteRecord)(16, idc);
     }//for(int i = 1; i <= type_16_number_of_records; i++)

}//if(pCheckIfRecordTypeExists(16) == 1)




   //Sets output file name as "sample_of_deletion.nist" (in "output" subdirectory)
   filedirectory[0] = 0;
   filename[0] = 0;
   wcscat(filedirectory, program_file_path);
   wcscat(filedirectory, L"output\\");
   if(!DirectoryExists(filedirectory))
   {
   // Create output directory
   _wmkdir(filedirectory);
   }

   wcscat(filename, filedirectory);
   wcscat(filename, L"sample_of_deletion.nist");


   //Saves NIST into the file "sample_of_deletion.nist" (in "output" subdirectory)
   (pWriteNISTToFile)(System::UTF8Encode(String(filename)).c_str());

    Application->MessageBox(L"NIST file \".\\input\\sample.nist\" was read, modified\nand saved as \".\\output\\sample_of_deletion.nist\"\nPlease use \"NIST viewer\" to see changes in\n\"sample_of_deletion.nist\" file.", L"NIST Library Demo", MB_OK);



    CreateAndInsertButton->Enabled = true;
    ReadAndModifyButton->Enabled = true;
    ReadAndExportButton->Enabled = true;
    ReadSingleFieldButton->Enabled = true;
    DeleteSingleFieldButton->Enabled = true;
    RegisterButton->Enabled = true;
    Screen->Cursor = crDefault;


}
//---------------------------------------------------------------------------

