unit nist_demo_main_form;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
  Windows;

type

  { TMainForm }

  TMainForm = class(TForm)
    DeleteSingleFieldButton: TButton;
    ReadSingleFieldButton: TButton;
    CreateAndInsertButton: TButton;
    ReadAndModifyButton: TButton;
    RegisterButton: TButton;
    ReadAndExportButton: TButton;
    OutputImage: TImage;
    procedure CreateAndInsertButtonClick(Sender: TObject);
    procedure DeleteSingleFieldButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ReadAndExportButtonClick(Sender: TObject);
    procedure ReadAndModifyButtonClick(Sender: TObject);
    procedure ReadSingleFieldButtonClick(Sender: TObject);
    procedure RegisterButtonClick(Sender: TObject);
  private

  public

  end;

{NIST library declaration of functions}

function RegisterNIST(): Integer; cdecl; external 'NIST_library.dll' name '_RegisterNIST';
function CreateNewNISTFile(): Integer; cdecl; external 'NIST_library.dll' name '_CreateNewNISTFile';
function WriteNISTToFile(const filename: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_WriteNISTToFile';
function ReadNISTByteArray(): PByte;  cdecl; external 'NIST_library.dll' name '_ReadNISTByteArray';
function ReadSizeOfNISTByteArray(): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfNISTByteArray';
function ReadNISTFromFile(const filename: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_ReadNISTFromFile';
function ReadNISTFromMemory(const inputbytearray: PByte; const sizeofinputbytearray: Integer): Integer; cdecl; external 'NIST_library.dll' name '_ReadNISTFromMemory';
function CheckIfRecordTypeExists(const recordtypenumber: Integer): Integer; cdecl; external 'NIST_library.dll' name '_CheckIfRecordTypeExists';
function ReadNumberOfRecords(const recordtypenumber: Integer): Integer; cdecl; external 'NIST_library.dll' name '_ReadNumberOfRecords';
function ReadIDCofRecord(const recordtypenumber: Integer; const recordnumber: Integer): Integer; cdecl; external 'NIST_library.dll' name '_ReadIDCofRecord';
function ReadRecordTxtField(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar): PAnsiChar; cdecl; external 'NIST_library.dll' name '_ReadRecordTxtField';
function ReadSizeOfRecordTxtField(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfRecordTxtField';
function ReadRecordTxtFieldName(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer): PAnsiChar; cdecl; external 'NIST_library.dll' name '_ReadRecordTxtFieldName';
function ReadSizeOfRecordTxtFieldName(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfRecordTxtFieldName';
function ReadRecordTxtFieldDescription(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar): PAnsiChar; cdecl; external 'NIST_library.dll' name '_ReadRecordTxtFieldDescription';
function ReadSizeOfRecordTxtFieldDescription(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfRecordTxtFieldDescription';
function ReadRecordExportedTxtFields(const recordtypenumber: Integer; const idc: Integer): PAnsiChar; cdecl; external 'NIST_library.dll' name '_ReadRecordExportedTxtFields';
function ReadSizeOfRecordExportedTxtFields(const recordtypenumber: Integer; const idc: Integer): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfRecordExportedTxtFields';
function ReadRecordBinaryField(const recordtypenumber: Integer; const idc: Integer): PByte; cdecl; external 'NIST_library.dll' name '_ReadRecordBinaryField';
function ReadSizeOfRecordBinaryField(const recordtypenumber: Integer; const idc: Integer): Integer; cdecl; external 'NIST_library.dll' name '_ReadSizeOfRecordBinaryField';
function CreateHBITMAPfromRecordBinaryField(const recordtypenumber: Integer; const idc: Integer): Integer; cdecl; external 'NIST_library.dll' name '_CreateHBITMAPfromRecordBinaryField';
function InsertRecordBinaryFieldFromFile(const recordtypenumber: Integer; const idc: Integer; const filename: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_InsertRecordBinaryFieldFromFile';
function InsertRecordBinaryFieldFromMemory(const recordtypenumber: Integer; const idc: Integer; const inputbytearray: PByte; const sizeofinputbytearray: Integer; const CGA: PByte; const CGAint: Integer; const HLL: Integer; const VLL: Integer): Integer; cdecl; external 'NIST_library.dll' name '_InsertRecordBinaryFieldFromMemory';
function InsertRecordTxtField(const recordtypenumber: Integer; const idc: Integer; const recordfieldnumber: Integer; const recordfieldname: PAnsiChar; const inputdata: PAnsiChar): Integer; cdecl; external 'NIST_library.dll' name '_InsertRecordTxtField';
function DeleteRecord(const recordtypenumber: Integer; const idc: Integer): Integer; cdecl; external 'NIST_library.dll' name '_DeleteRecord';
function SetAnsiNistItlVersion(const version_year: Integer; const traditional_or_xml: Integer): Integer; cdecl; external 'NIST_library.dll' name '_SetAnsiNistItlVersion';





var
  MainForm: TMainForm;

  open_dialog: TOpenDialog;
  bitmap: HBitmap;

  idc_current: Integer;
  idc: Integer;

  program_file_path: String;
  filedirectory: String;
  filename: String;
  image_compression_code: String;

  iFileHandle, iFileLength, i: Integer;
  size_of_byte_array: Integer;
  byte_array: PByte;
  size: Integer;
  nist_txt_field: AnsiString;
  nist_binary_field: PByte;
  nist_int_field: Integer;
  type_2_number_of_records: Integer;
  type_3_number_of_records: Integer;
  type_4_number_of_records: Integer;
  type_5_number_of_records: Integer;
  type_6_number_of_records: Integer;
  type_7_number_of_records: Integer;
  type_8_number_of_records: Integer;
  type_9_number_of_records: Integer;
  type_10_number_of_records: Integer;
  type_11_number_of_records: Integer;
  type_12_number_of_records: Integer;
  type_13_number_of_records: Integer;
  type_14_number_of_records: Integer;
  type_15_number_of_records: Integer;
  type_16_number_of_records: Integer;
  type_17_number_of_records: Integer;
  type_18_number_of_records: Integer;
  type_19_number_of_records: Integer;
  type_20_number_of_records: Integer;
  type_21_number_of_records: Integer;
  type_22_number_of_records: Integer;
  type_98_number_of_records: Integer;
  type_99_number_of_records: Integer;
  output_message: String;

  traditional_or_xml_format: Integer;



implementation

{$R *.lfm}

{ TMainForm }

procedure TMainForm.FormShow(Sender: TObject);
begin

  Left := (Screen.Width - Width) div 2;
  Top := (Screen.Height - Height) div 2;

end;


procedure TMainForm.FormCreate(Sender: TObject);
begin

  open_dialog := TOpenDialog.Create(MainForm);
  open_dialog.Filter := 'All NIST files|*.nist;*.an2;*.eft;*.xml|NIST files (*.nist)|*.nist|AN2 files (*.an2)|*.an2|EFT files (*.eft)|*.eft|NIEM-conformant XML files (*.xml)|*.xml|All files (*.*)|*.*';

  program_file_path := ExtractFilePath(Application.ExeName);

  traditional_or_xml_format := 0; // traditional format

end;


procedure TMainForm.FormDestroy(Sender: TObject);
begin

  open_dialog.Destroy;

end;


procedure TMainForm.CreateAndInsertButtonClick(Sender: TObject);
begin

  CreateAndInsertButton.Enabled := false;
  ReadAndModifyButton.Enabled := false;
  ReadAndExportButton.Enabled := false;
  ReadSingleFieldButton.Enabled := false;
  DeleteSingleFieldButton.Enabled := false;
  RegisterButton.Enabled := false;
  Screen.Cursor := crHourGlass;


  // In function SetAnsiNistItlVersion(int version_year, int traditional_or_xml)
  // first argument denotes version year ANSI/NIST-ITL standard, possible values: 1986, 1993, 1997, 2000, 2007, 2009, 2011, 2013, 2015
  // second argument denotes nist file format. 0 denotes traditional format, 1 denotes NIEM-conformant XML format.

  traditional_or_xml_format := 0; // traditional format
  //traditional_or_xml_format := 1; // NIEM-conformant XML format
  SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format


  // Creates new empty NIST file
  CreateNewNISTFile();


  // ===========================
  Application.MessageBox(PChar('Inserting/replacing Type-1 and Type-2 records...'), PChar('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.
  // InsertType1Record('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'.
  // InsertType1Record('VER', '0300');

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

  // Modifies NIST file, inserts/replaces Type-1 record date (DAT)
  InsertRecordTxtField(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
  InsertRecordTxtField(1, -1, -1, 'PRY', '1');

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

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

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

  // Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
  InsertRecordTxtField(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
  InsertRecordTxtField(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
  InsertRecordTxtField(1, -1, -1, 'NTR', '19.69');

  // Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
  InsertRecordTxtField(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
  if(traditional_or_xml_format = 0) then
  InsertRecordTxtField(1, -1, -1, 'GMT', '20081031152345Z')
  else
  InsertRecordTxtField(1, -1, -1, 'GMT', '2008-10-31T15:23:45Z');


  // 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 := InsertRecordTxtField(2, -1, 30, '', 'James Clerk');
  InsertRecordTxtField(2, idc_current, 31, '', 'Maxwell');
  InsertRecordTxtField(2, idc_current, 32, '', 'Berlin, Germany');

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

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



  // Sets input directory as 'input' subdirectory of the program location
  filedirectory := program_file_path + 'input' + PathDelim;


  Application.MessageBox(PChar('Inserting/replacing Type-4 records...'), PChar('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 := filedirectory + 'type4_01.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');



  filename := filedirectory + 'type4_02.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_03.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_04.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_05.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_06.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_07.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');



  filename := filedirectory + 'type4_08.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_09.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_10.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_11.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_12.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_13.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_14.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, -1, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // 'NIST library' inserts GCA value '1' automatically when creating Type-4 record, based on PAnsiChar(filename) *.wsq extension, here you can overwrite it with new value if needed
  // InsertRecordTxtField(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.
  // '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(PChar('Inserting/replacing Type-7 records...'), PChar('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 := filedirectory + 'type7_01.jpg';
  idc_current := InsertRecordBinaryFieldFromFile(7, -1, PAnsiChar(filename));

  InsertRecordTxtField(7, idc_current, -1, 'IMT', '1');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(7, idc_current, -1, 'GCA', '3');

  filename := filedirectory + 'type7_02.jpg';
  idc_current := InsertRecordBinaryFieldFromFile(7, -1, PAnsiChar(filename));

  InsertRecordTxtField(7, idc_current, -1, 'IMT', '1');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(7, idc_current, -1, 'GCA', '3');

  filename := filedirectory + 'type7_03.jpg';
  idc_current := InsertRecordBinaryFieldFromFile(7, -1, PAnsiChar(filename));

  InsertRecordTxtField(7, idc_current, -1, 'IMT', '1');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(7, idc_current, -1, 'GCA', '3');


  filename := filedirectory + 'type7_04.jpg';
  idc_current := InsertRecordBinaryFieldFromFile(7, -1, PAnsiChar(filename));

  InsertRecordTxtField(7, idc_current, -1, 'IMT', '1');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(7, idc_current, -1, 'GCA', '3');



  Application.MessageBox(PChar('Inserting/replacing Type-8 records...'), PChar('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 := filedirectory + 'type8_01.bin';
  idc_current := InsertRecordBinaryFieldFromFile(8, -1, PAnsiChar(filename));

  InsertRecordTxtField(8, idc_current, -1, 'SIG', '0');
  InsertRecordTxtField(8, idc_current, -1, 'SRT', '0');
  InsertRecordTxtField(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
  InsertRecordTxtField(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
  InsertRecordTxtField(8, idc_current, -1, 'VLL', '500');


  filename := filedirectory + 'type8_02.bin';
  idc_current := InsertRecordBinaryFieldFromFile(8, -1, PAnsiChar(filename));

  InsertRecordTxtField(8, idc_current, -1, 'SIG', '1');
  InsertRecordTxtField(8, idc_current, -1, 'SRT', '0');
  InsertRecordTxtField(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
  InsertRecordTxtField(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
  InsertRecordTxtField(8, idc_current, -1, 'VLL', '500');




  Application.MessageBox(PChar('Inserting/replacing Type-10 records...'), PChar('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 := filedirectory + 'type10_01.jpg';
  // filename := filedirectory + 'type10_01.png';
  // filename := filedirectory + 'type10_01.jp2';

  idc_current := InsertRecordBinaryFieldFromFile(10, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(10, idc_current, -1, 'THPS', '300');

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(10, idc_current, -1, 'TVPS', '300');

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

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

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


  // filename := filedirectory + 'type10_02.jpg';
  filename := filedirectory + 'type10_02.png';
  // filename := filedirectory + 'type10_02.jp2';

  idc_current := InsertRecordBinaryFieldFromFile(10, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(10, idc_current, -1, 'THPS', '300');

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(10, idc_current, -1, 'TVPS', '300');

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

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

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


  // filename := filedirectory + 'type10_03.jpg';
  // filename := filedirectory + 'type10_03.png';
  filename := filedirectory + 'type10_03.jp2';


  idc_current := InsertRecordBinaryFieldFromFile(10, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(10, idc_current, -1, 'THPS', '300');

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(10, idc_current, -1, 'TVPS', '300');

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

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

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



  Application.MessageBox(PChar('Inserting/replacing Type-13 records...'), PChar('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 := filedirectory + 'type13_01.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(13, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-13 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(13, idc_current, -1, 'THPS', '197');

  // Modifies NIST file, inserts/replaces mandatory Type-13 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(13, idc_current, -1, 'TVPS', '197');

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

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

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



  Application.MessageBox(PChar('Inserting/replacing Type-14 records...'), PChar('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 := filedirectory + 'type14_01.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(14, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(14, idc_current, -1, 'THPS', '197');

  // Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(14, idc_current, -1, 'TVPS', '197');

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

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

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



  Application.MessageBox(PChar('Inserting/replacing Type-15 records...'), PChar('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 := filedirectory + 'type15_01.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(15, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(15, idc_current, -1, 'THPS', '500');

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(15, idc_current, -1, 'TVPS', '500');

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

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

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



  filename := filedirectory + 'type15_02.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(15, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(15, idc_current, -1, 'THPS', '500');

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(15, idc_current, -1, 'TVPS', '500');

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

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

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


  filename := filedirectory + 'type15_03.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(15, -1, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(15, idc_current, -1, 'THPS', '500');

  // Modifies NIST file, inserts/replaces mandatory Type-15 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(15, idc_current, -1, 'TVPS', '500');

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

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

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



  Application.MessageBox(PChar('Inserting/replacing Type-16 records...'), PChar('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 := filedirectory + 'type16_01.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(16, -1, PAnsiChar(filename));

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-16 record
  InsertRecordTxtField(16, idc_current, -1, 'THPS', '500');

  // Modifies NIST file, inserts/replaces mandatory Type-16 record
  InsertRecordTxtField(16, idc_current, -1, 'TVPS', '500');

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

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

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

  // ===========================



  // Sets output file name as "sample_new.nist" (in "output" subdirectory)
  filedirectory := program_file_path + 'output' + PathDelim;

  if not DirectoryExists(filedirectory) then
  begin
    // Create output directory
    CreateDir(filedirectory);
  end;

  if(traditional_or_xml_format = 0) then
  filename := filedirectory + 'sample_new.nist'
  else
  filename := filedirectory + 'sample_new.xml';


  // Saves NIST into the file "sample_new.nist" (in "output" subdirectory)
  // WriteNISTToFile(PAnsiChar(filename));

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

  iFileHandle := FileCreate(filename);
  FileWrite(iFileHandle, byte_array^, size_of_byte_array);
  FileClose(iFileHandle);
  // ==========================



  if(traditional_or_xml_format = 0) then
  Application.MessageBox(PChar('New NIST file was created, modified and saved as' + LineEnding + '".' + PathDelim + 'output' + PathDelim + 'sample_new.nist"' + LineEnding + LineEnding + 'Please use "NIST viewer" to view' + LineEnding + '"sample_new.nist" file.'), PChar('NIST library'), MB_OK)
  else
  Application.MessageBox(PChar('New NIST file was created, modified and saved as' + LineEnding + '".' + PathDelim + 'output' + PathDelim + 'sample_new.xml"' + LineEnding + LineEnding + 'Please use "NIST viewer" to view' + LineEnding + '"sample_new.xml" file.'), PChar('NIST library'), MB_OK);


  CreateAndInsertButton.Enabled := True;
  ReadAndModifyButton.Enabled := True;
  ReadAndExportButton.Enabled := True;
  ReadSingleFieldButton.Enabled := True;
  DeleteSingleFieldButton.Enabled := True;
  RegisterButton.Enabled := True;
  Screen.Cursor := crDefault;

end;

procedure TMainForm.DeleteSingleFieldButtonClick(Sender: TObject);
begin

  CreateAndInsertButton.Enabled := false;
  ReadAndModifyButton.Enabled := false;
  ReadAndExportButton.Enabled := false;
  ReadSingleFieldButton.Enabled := false;
  DeleteSingleFieldButton.Enabled := false;
  RegisterButton.Enabled := false;
  Screen.Cursor := crHourGlass;



  traditional_or_xml_format := 0; // traditional format
  //traditional_or_xml_format := 1; // NIEM-conformant XML format
  SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format


  // Sets input file name as "sample.nist" which located in "input" subdirectory
  filedirectory := program_file_path + 'input' + PathDelim;

  if(traditional_or_xml_format = 0) then
  filename := filedirectory + 'sample.nist'
  else
  filename := filedirectory + 'sample_NIEM_conformant_XML.xml';



  if not FileExists(filename) then
  begin
    if(traditional_or_xml_format = 0) then
    Application.MessageBox(PChar('Error: file .' + PathDelim + 'input' + PathDelim + 'sample.nist does not exist.'), PChar('Error'), MB_OK)
    else
    Application.MessageBox(PChar('Error: file .' + PathDelim + 'input' + PathDelim + 'sample_NIEM_conformant_XML.xml does not exist.'), PChar('Error'), MB_OK);
	
    Exit();
  end;



  // 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.
  ReadNISTFromFile(PAnsiChar(filename));




  if (CheckIfRecordTypeExists(2) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-2 records
    type_2_number_of_records := ReadNumberOfRecords(2);

    for i := 1 to type_2_number_of_records do
    begin
      // idc := ReadIDCofRecord(2, 1); // selects the first Type-2 record
      idc := ReadIDCofRecord(2, (type_2_number_of_records - i + 1));
      // selects the last Type-2 record
      DeleteRecord(2, idc);
    end; // for(int i = 1; i <= type_2_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(2) = 1)


  if (CheckIfRecordTypeExists(3) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-3 records
    type_3_number_of_records := ReadNumberOfRecords(3);

    for i := 1 to type_3_number_of_records do
    begin
      // idc := ReadIDCofRecord(3, 1); // selects the first Type-3 record
      idc := ReadIDCofRecord(3, (type_3_number_of_records - i + 1));
      // selects the last Type-3 record
      DeleteRecord(3, idc);
    end; // for(int i = 1; i <= type_3_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(3) = 1)


  if (CheckIfRecordTypeExists(4) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-4 records
    type_4_number_of_records := ReadNumberOfRecords(4);

    for i := 1 to type_4_number_of_records do
    begin
      // idc := ReadIDCofRecord(4, 1); // selects the first Type-4 record
      idc := ReadIDCofRecord(4, (type_4_number_of_records - i + 1));
      // selects the last Type-4 record
      DeleteRecord(4, idc);
    end; // for(int i = 1; i <= type_4_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(4) = 1)


  if (CheckIfRecordTypeExists(5) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-5 records
    type_5_number_of_records := ReadNumberOfRecords(5);

    for i := 1 to type_5_number_of_records do
    begin
      // idc := ReadIDCofRecord(5, 1); // selects the first Type-5 record
      idc := ReadIDCofRecord(5, (type_5_number_of_records - i + 1));
      // selects the last Type-5 record
      DeleteRecord(5, idc);
    end; // for(int i = 1; i <= type_5_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(5) = 1)


  if (CheckIfRecordTypeExists(6) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-6 records
    type_6_number_of_records := ReadNumberOfRecords(6);

    for i := 1 to type_6_number_of_records do
    begin
      // idc := ReadIDCofRecord(6, 1); // selects the first Type-6 record
      idc := ReadIDCofRecord(6, (type_6_number_of_records - i + 1));
      // selects the last Type-6 record
      DeleteRecord(6, idc);
    end; // for(int i = 1; i <= type_6_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(6) = 1)


  if (CheckIfRecordTypeExists(7) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-7 records
    type_7_number_of_records := ReadNumberOfRecords(7);

    for i := 1 to type_7_number_of_records do
    begin
      // idc := ReadIDCofRecord(7, 1); // selects the first Type-7 record
      idc := ReadIDCofRecord(7, (type_7_number_of_records - i + 1));
      // selects the last Type-7 record
      DeleteRecord(7, idc);
    end; // for(int i = 1; i <= type_7_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(7) = 1)


  if (CheckIfRecordTypeExists(8) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-8 records
    type_8_number_of_records := ReadNumberOfRecords(8);

    for i := 1 to type_8_number_of_records do
    begin
      // idc := ReadIDCofRecord(8, 1); // selects the first Type-8 record
      idc := ReadIDCofRecord(8, (type_8_number_of_records - i + 1));
      // selects the last Type-8 record
      DeleteRecord(8, idc);
    end; // for(int i = 1; i <= type_8_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(8) = 1)


  if (CheckIfRecordTypeExists(9) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-9 records
    type_9_number_of_records := ReadNumberOfRecords(9);

    for i := 1 to type_9_number_of_records do
    begin
      // idc := ReadIDCofRecord(9, 1); // selects the first Type-9 record
      idc := ReadIDCofRecord(9, (type_9_number_of_records - i + 1));
      // selects the last Type-9 record
      DeleteRecord(9, idc);
    end; // for(int i = 1; i <= type_9_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(9) = 1)


  if (CheckIfRecordTypeExists(10) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-10 records
    type_10_number_of_records := ReadNumberOfRecords(10);

    for i := 1 to type_10_number_of_records do
    begin
      // idc := ReadIDCofRecord(10, 1); // selects the first Type-10 record
      idc := ReadIDCofRecord(10, (type_10_number_of_records - i + 1));
      // selects the last Type-10 record
      DeleteRecord(10, idc);
    end; // for(int i = 1; i <= type_10_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(10) = 1)


  if (CheckIfRecordTypeExists(11) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-11 records
    type_11_number_of_records := ReadNumberOfRecords(11);

    for i := 1 to type_11_number_of_records do
    begin
      // idc := ReadIDCofRecord(11, 1); // selects the first Type-11 record
      idc := ReadIDCofRecord(11, (type_11_number_of_records - i + 1));
      // selects the last Type-11 record
      DeleteRecord(11, idc);
    end; // for(int i = 1; i <= type_11_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(11) = 1)


  if (CheckIfRecordTypeExists(12) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-12 records
    type_12_number_of_records := ReadNumberOfRecords(12);

    for i := 1 to type_12_number_of_records do
    begin
      // idc := ReadIDCofRecord(12, 1); // selects the first Type-12 record
      idc := ReadIDCofRecord(12, (type_12_number_of_records - i + 1));
      // selects the last Type-12 record
      DeleteRecord(12, idc);
    end; // for(int i = 1; i <= type_12_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(12) = 1)


  if (CheckIfRecordTypeExists(13) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-13 records
    type_13_number_of_records := ReadNumberOfRecords(13);

    for i := 1 to type_13_number_of_records do
    begin
      // idc := ReadIDCofRecord(13, 1); // selects the first Type-13 record
      idc := ReadIDCofRecord(13, (type_13_number_of_records - i + 1));
      // selects the last Type-13 record
      DeleteRecord(13, idc);
    end; // for(int i = 1; i <= type_13_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(13) = 1)


  if (CheckIfRecordTypeExists(14) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-14 records
    type_14_number_of_records := ReadNumberOfRecords(14);

    for i := 1 to type_14_number_of_records do
    begin
      // idc := ReadIDCofRecord(14, 1); // selects the first Type-14 record
      idc := ReadIDCofRecord(14, (type_14_number_of_records - i + 1));
      // selects the last Type-14 record
      DeleteRecord(14, idc);
    end; // for(int i = 1; i <= type_14_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(14) = 1)


  if (CheckIfRecordTypeExists(15) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-15 records
    type_15_number_of_records := ReadNumberOfRecords(15);

    for i := 1 to type_15_number_of_records do
    begin
      // idc := ReadIDCofRecord(15, 1); // selects the first Type-15 record
      idc := ReadIDCofRecord(15, (type_15_number_of_records - i + 1));
      // selects the last Type-15 record
      DeleteRecord(15, idc);
    end; // for(int i = 1; i <= type_15_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(15) = 1)


  if (CheckIfRecordTypeExists(16) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-16 records
    type_16_number_of_records := ReadNumberOfRecords(16);

    for i := 1 to type_16_number_of_records do
    begin
      // idc := ReadIDCofRecord(16, 1); // selects the first Type-16 record
      idc := ReadIDCofRecord(16, (type_16_number_of_records - i + 1));
      // selects the last Type-16 record
      DeleteRecord(16, idc);
    end; // for(int i = 1; i <= type_16_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(16) = 1)


  if (CheckIfRecordTypeExists(17) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-17 records
    type_17_number_of_records := ReadNumberOfRecords(17);

    for i := 1 to type_17_number_of_records do
    begin
      // idc := ReadIDCofRecord(17, 1); // selects the first Type-17 record
      idc := ReadIDCofRecord(17, (type_17_number_of_records - i + 1));
      // selects the last Type-17 record
      DeleteRecord(17, idc);
    end; // for(int i = 1; i <= type_17_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(17) = 1)


  if (CheckIfRecordTypeExists(18) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-18 records
    type_18_number_of_records := ReadNumberOfRecords(18);

    for i := 1 to type_18_number_of_records do
    begin
      // idc := ReadIDCofRecord(18, 1); // selects the first Type-18 record
      idc := ReadIDCofRecord(18, (type_18_number_of_records - i + 1));
      // selects the last Type-18 record
      DeleteRecord(18, idc);
    end; // for(int i = 1; i <= type_18_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(18) = 1)


  if (CheckIfRecordTypeExists(19) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-19 records
    type_19_number_of_records := ReadNumberOfRecords(19);

    for i := 1 to type_19_number_of_records do
    begin
      // idc := ReadIDCofRecord(19, 1); // selects the first Type-19 record
      idc := ReadIDCofRecord(19, (type_19_number_of_records - i + 1));
      // selects the last Type-19 record
      DeleteRecord(19, idc);
    end; // for(int i = 1; i <= type_19_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(19) = 1)

  if (CheckIfRecordTypeExists(20) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-20 records
    type_20_number_of_records := ReadNumberOfRecords(20);

    for i := 1 to type_20_number_of_records do
    begin
      // idc := ReadIDCofRecord(20, 1); // selects the first Type-20 record
      idc := ReadIDCofRecord(20, (type_20_number_of_records - i + 1));
      // selects the last Type-20 record
      DeleteRecord(20, idc);
    end; // for(int i = 1; i <= type_20_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(20) = 1)


  if (CheckIfRecordTypeExists(21) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-21 records
    type_21_number_of_records := ReadNumberOfRecords(21);

    for i := 1 to type_21_number_of_records do
    begin
      // idc := ReadIDCofRecord(21, 1); // selects the first Type-21 record
      idc := ReadIDCofRecord(21, (type_21_number_of_records - i + 1));
      // selects the last Type-21 record
      DeleteRecord(21, idc);
    end; // for(int i = 1; i <= type_21_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(21) = 1)


  if (CheckIfRecordTypeExists(22) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-22 records
    type_22_number_of_records := ReadNumberOfRecords(22);

    for i := 1 to type_22_number_of_records do
    begin
      // idc := ReadIDCofRecord(22, 1); // selects the first Type-22 record
      idc := ReadIDCofRecord(22, (type_22_number_of_records - i + 1));
      // selects the last Type-22 record
      DeleteRecord(22, idc);
    end; // for(int i = 1; i <= type_22_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(22) = 1)


  if (CheckIfRecordTypeExists(98) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-98 records
    type_98_number_of_records := ReadNumberOfRecords(98);

    for i := 1 to type_98_number_of_records do
    begin
      // idc := ReadIDCofRecord(98, 1); // selects the first Type-98 record
      idc := ReadIDCofRecord(98, (type_98_number_of_records - i + 1));
      // selects the last Type-98 record
      DeleteRecord(98, idc);
    end; // for(int i = 1; i <= type_98_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(98) = 1)


  if (CheckIfRecordTypeExists(99) = 1) then
  begin
    // Modifies NIST file, Deletes all Type-99 records
    type_99_number_of_records := ReadNumberOfRecords(99);

    for i := 1 to type_99_number_of_records do
    begin
      // idc := ReadIDCofRecord(99, 1); // selects the first Type-99 record
      idc := ReadIDCofRecord(99, (type_99_number_of_records - i + 1));
      // selects the last Type-99 record
      DeleteRecord(99, idc);
    end; // for(int i = 1; i <= type_99_number_of_records; i++)

  end; // if(CheckIfRecordTypeExists(99) = 1)



  // Sets output file name as "sample_of_deletion.nist" (in "output" subdirectory)
  filedirectory := program_file_path + 'output' + PathDelim;

  if not DirectoryExists(filedirectory) then
  begin
    // Create output directory
    CreateDir(filedirectory);
  end;

  if(traditional_or_xml_format = 0) then
  filename := filedirectory + 'sample_of_deletion.nist'
  else
  filename := filedirectory + 'sample_of_deletion.xml';


  // Saves NIST into the file 'sample_modified.nist' (in "output" subdirectory)
  WriteNISTToFile(PAnsiChar(filename));

  if(traditional_or_xml_format = 0) then
  Application.MessageBox(PChar('NIST file ".' + PathDelim + 'input' + PathDelim + 'sample.nist" was read, modified' + LineEnding + 'and saved as ".' + PathDelim + 'output' + PathDelim + 'sample_of_deletion.nist"' + LineEnding + LineEnding + 'Please use "NIST viewer" to see changes in' + LineEnding + '"sample_of_deletion.nist" file.'), PChar('NIST library'), MB_OK)
  else
  Application.MessageBox(PChar('NIST file ".' + PathDelim + 'input' + PathDelim + 'sample_NIEM_conformant_XML.xml" was read, modified' + LineEnding + 'and saved as ".' + PathDelim + 'output' + PathDelim + 'sample_of_deletion.xml"' + LineEnding + LineEnding + 'Please use "NIST viewer" to see changes in' + LineEnding + '"sample_of_deletion.xml" file.'), PChar('NIST library'), MB_OK);




  CreateAndInsertButton.Enabled := True;
  ReadAndModifyButton.Enabled := True;
  ReadAndExportButton.Enabled := True;
  ReadSingleFieldButton.Enabled := True;
  DeleteSingleFieldButton.Enabled := True;
  RegisterButton.Enabled := True;
  Screen.Cursor := crDefault;

end;

procedure TMainForm.ReadAndExportButtonClick(Sender: TObject);
begin

  if not open_dialog.Execute() then
  begin
    exit;
  end;


  bitmap := HBitmap(nil);

  filedirectory := program_file_path + 'output' + PathDelim;

  if not DirectoryExists(filedirectory) then
  begin
    // Create output directory
    CreateDir(filedirectory);
  end;




  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.
  // ReadNISTFromFile(PByte(open_dialog.FileName));


  // Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
  // ==========================
  iFileHandle := FileOpen(open_dialog.FileName, fmOpenRead);
  iFileLength := FileSeek(iFileHandle, 0, 2);
  FileSeek(iFileHandle, 0, 0);
  byte_array := PByte(AllocMem(iFileLength + 1));
  size_of_byte_array := FileRead(iFileHandle, byte_array^, iFileLength);
  FileClose(iFileHandle);

  // 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.
  ReadNISTFromMemory(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 <> PByte(nil)) then
  begin
    FreeMem(byte_array);
    byte_array := PByte(nil);
  end;
  // ==========================

  if (CheckIfRecordTypeExists(1) = 1) then
  begin
    // Returns size of text NIST field.
    size := ReadSizeOfRecordExportedTxtFields(1, 0);
    // Returns contents of NIST file data field as text string (char array).
    nist_txt_field := ReadRecordExportedTxtFields(1, 0);

    // Sets filename for saving exported data of text field from type 1 record
    iFileHandle := FileCreate(filedirectory + 'type1.txt');
    // Writes exported data of text field from type 1 record to the file
    FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
    FileClose(iFileHandle);

    Application.MessageBox(PChar('Type-1 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type1.txt'), PChar('NIST library'), MB_OK);
  end; // if(CheckIfRecordTypeExists(1) = 1)


  if (CheckIfRecordTypeExists(2) = 1) then
  begin

    type_2_number_of_records := ReadNumberOfRecords(2);

    for i := 1 to type_2_number_of_records do
    begin
      idc := ReadIDCofRecord(2, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 2 record
        iFileHandle := FileCreate(filedirectory + 'type2_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 2 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;


      Application.MessageBox(PChar('Type-2 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type2_' + IntToStr(idc) + '.txt'), PChar('NIST library'), MB_OK);

    end; // for i := 1 to type_2_number_of_records do
  end; // if(CheckIfRecordTypeExists(2) = 1)


  if (CheckIfRecordTypeExists(4) = 1) then
  begin

    type_4_number_of_records := ReadNumberOfRecords(4);

    // In type 4 record there might be up to 14 fingerprint images.
    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_4_number_of_records do
    begin
      idc := ReadIDCofRecord(4, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 4 record
        iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 4 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 4 record
        image_compression_code := ReadRecordTxtField(4, idc, -1, 'GCA');

        output_message := 'Type-4 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type4_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-4 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type4_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type4_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'High-resolution grayscale fingerprint image was extracted from Type-4 record' + LineEnding + 'binary 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
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(4, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;


        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-4 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type4_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-4 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type4_' + IntToStr(i) + '.wsq' + LineEnding + 'High-resolution grayscale fingerprint image was extracted from type 4 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_4_number_of_records do
  end; // if(CheckIfRecordTypeExists(4) = 1)


  if (CheckIfRecordTypeExists(7) = 1) then
  begin

    type_7_number_of_records := ReadNumberOfRecords(7);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_7_number_of_records do
    begin
      idc := ReadIDCofRecord(7, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 7 record
        iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 7 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 7 record
        image_compression_code := ReadRecordTxtField(7, idc, -1, 'GCA');

        output_message := 'Type-7 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type7_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-7 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type7_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type7_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'User-defined image was extracted from Type-7 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';



        // Writes exported data of binary field from type 7 record to the file
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(7, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-7 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type7_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-7 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type7_' + IntToStr(i) + '.jpg' + LineEnding + 'User-defined image was extracted from type 7 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_7_number_of_records do
  end; // if(CheckIfRecordTypeExists(7) = 1)




  if (CheckIfRecordTypeExists(8) = 1) then
  begin

    type_8_number_of_records := ReadNumberOfRecords(8);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_8_number_of_records do
    begin
      idc := ReadIDCofRecord(8, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 8 record
        iFileHandle := FileCreate(filedirectory + 'type8_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 8 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        output_message := 'Type-8 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type8_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-8 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type8_' + IntToStr(i) + '.bin.';
        output_message := output_message + LineEnding + LineEnding + 'Signature image was extracted from Type-8 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';

        // Sets filename for saving exported data of binary field from type 8 record
        iFileHandle := FileCreate(filedirectory + 'type8_' + IntToStr(i) + '.bin');
        // Writes exported data of binary field from type 8 record to the file
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(8, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-8 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type8_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-8 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type8_' + IntToStr(i) + '.bin' + LineEnding + 'Signature image was extracted from type 8 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_8_number_of_records do
  end; // if(CheckIfRecordTypeExists(8) = 1)




  if (CheckIfRecordTypeExists(9) = 1) then
  begin

    type_9_number_of_records := ReadNumberOfRecords(9);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_9_number_of_records do
    begin
      idc := ReadIDCofRecord(9, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 9 record
        iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 9 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 9 record
        // image_compression_code := ReadRecordTxtField(9, idc, -1, 'GCA');

        output_message := 'Type-9 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type9_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-9 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type9_' + IntToStr(i);

        // if((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        // begin
        // iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.bin');
        // output_message := output_message + '.bin';
        // end
        // else if((image_compression_code = '1') or (image_compression_code = 'WSQ20') or (image_compression_code = 'WSQ')) then
        // begin
        // iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.wsq');
        // output_message := output_message + '.wsq';
        // end
        // else if((image_compression_code = '2') or (image_compression_code = 'JPEGB') or (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        // begin
        // iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.jpg');
        // output_message := output_message + '.jpg';
        // end
        // else if((image_compression_code = '4') or (image_compression_code = 'JP2') or (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        // begin
        // iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.jp2');
        // output_message := output_message + '.jp2';
        // end
        // else if((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        // begin
        // iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.png');
        // output_message := output_message + '.png';
        // end;

        output_message := output_message + LineEnding + LineEnding + 'Minutiae data was extracted from Type-9 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';


        iFileHandle := FileCreate(filedirectory + 'type9_' + IntToStr(i) + '.wsq');

        // Writes exported data of binary field from type 9 record to the file
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(9, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-9 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type9_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-9 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type9_' + IntToStr(i) + '.wsq' + LineEnding + 'Minutiae data was extracted from type 9 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_9_number_of_records do
  end; // if(CheckIfRecordTypeExists(9) = 1)



  if (CheckIfRecordTypeExists(10) = 1) then
  begin

    type_10_number_of_records := ReadNumberOfRecords(10);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_10_number_of_records do
    begin
      idc := ReadIDCofRecord(10, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 10 record
        iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 10 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 10 record
        image_compression_code := ReadRecordTxtField(10, idc, -1, 'CGA');

        output_message := 'Type-10 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type10_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-10 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type10_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type10_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'Facial & SMT image was extracted from Type-10 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';


        // Writes exported data of binary field from type 10 record to the file
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(10, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-10 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type10_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-10 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type10_' + IntToStr(i) + '.jpg' + LineEnding + 'Facial & SMT image was extracted from type 10 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_10_number_of_records do
  end; // if(CheckIfRecordTypeExists(10) = 1)


  if (CheckIfRecordTypeExists(13) = 1) then
  begin

    type_13_number_of_records := ReadNumberOfRecords(13);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_13_number_of_records do
    begin
      idc := ReadIDCofRecord(13, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 13 record
        iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 13 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 13 record
        image_compression_code := ReadRecordTxtField(13, idc, -1, 'CGA');

        output_message := 'Type-13 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type13_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-13 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type13_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type13_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'Variable-resolution latent image was extracted from Type-13 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';


        // Writes exported data of binary field from type 13 record to the file
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(13, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-13 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type13_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-13 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type13_' + IntToStr(i) + '.wsq' + LineEnding + 'Variable-resolution latent image was extracted from type 13 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_13_number_of_records do
  end; // if(CheckIfRecordTypeExists(13) = 1)



  if (CheckIfRecordTypeExists(14) = 1) then
  begin

    type_14_number_of_records := ReadNumberOfRecords(14);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_14_number_of_records do
    begin
      idc := ReadIDCofRecord(14, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 14 record
        iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 14 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 14 record
        image_compression_code := ReadRecordTxtField(14, idc, -1, 'CGA');

        output_message := 'Type-14 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type14_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-14 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type14_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type14_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'Variable-resolution fingerprint image was extracted from Type-14 record' + LineEnding + 'binary 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
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(14, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-14 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type14_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-14 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type14_' + IntToStr(i) + '.wsq' + LineEnding + 'Variable-resolution fingerprint image was extracted from type 14 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_14_number_of_records do
  end; // if(CheckIfRecordTypeExists(14) = 1)


  if (CheckIfRecordTypeExists(15) = 1) then
  begin

    type_15_number_of_records := ReadNumberOfRecords(15);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_15_number_of_records do
    begin
      idc := ReadIDCofRecord(15, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 15 record
        iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 15 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 15 record
        image_compression_code := ReadRecordTxtField(15, idc, -1, 'CGA');

        output_message := 'Type-15 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type15_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-15 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type15_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type15_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'Variable-resolution palmprint image was extracted from Type-15 record' + LineEnding + 'binary 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
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(15, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-15 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type15_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-15 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type15_' + IntToStr(i) + '.wsq' + LineEnding + 'Variable-resolution palmprint image was extracted from type 15 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_15_number_of_records do
  end; // if(CheckIfRecordTypeExists(15) = 1)



  if (CheckIfRecordTypeExists(16) = 1) then
  begin

    type_16_number_of_records := ReadNumberOfRecords(16);

    // Reads NIST file and exports all images to separate files.
    for i := 1 to type_16_number_of_records do
    begin
      idc := ReadIDCofRecord(16, i);

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

      if (size <> 0) then
      begin
        // Sets filename for saving exported data of text field from type 16 record
        iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.txt');
        // Writes exported data of text field from type 16 record to the file
        FileWrite(iFileHandle, (PByte(nist_txt_field))^, size);
        FileClose(iFileHandle);
      end;

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

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

      if (nist_binary_field <> PByte(nil)) then
      begin
        // Sets filename for saving exported data of binary field from type 16 record
        image_compression_code := ReadRecordTxtField(16, idc, -1, 'CGA');

        output_message := 'Type-16 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type16_' + IntToStr(i) + '.txt.' + LineEnding + LineEnding + 'Type-16 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type16_' + IntToStr(i);

        if ((image_compression_code = '0') or (image_compression_code = 'NONE')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.bin');
          output_message := output_message + '.bin';
        end
        else if ((image_compression_code = '1') or (image_compression_code = 'WSQ20') or
          (image_compression_code = 'WSQ')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.wsq');
          output_message := output_message + '.wsq';
        end
        else if ((image_compression_code = '2') or (image_compression_code = 'JPEGB') or
          (image_compression_code = '3') or (image_compression_code = 'JPEGL')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.jpg');
          output_message := output_message + '.jpg';
        end
        else if ((image_compression_code = '4') or (image_compression_code = 'JP2') or
          (image_compression_code = '5') or (image_compression_code = 'JP2L')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.jp2');
          output_message := output_message + '.jp2';
        end
        else if ((image_compression_code = '6') or (image_compression_code = 'PNG')) then
        begin
          iFileHandle := FileCreate(filedirectory + 'type16_' + IntToStr(i) + '.png');
          output_message := output_message + '.png';
        end;

        output_message := output_message + LineEnding + LineEnding + 'Variable-resolution user-defined testing image was extracted from Type-16 record' + LineEnding + 'binary 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
        FileWrite(iFileHandle, (PByte(nist_binary_field))^, size);
        FileClose(iFileHandle);

        // Converts NIST file binary field contents into HBITMAP image.
        // Returns image in HBITMAP format if successful, returns NULL otherwise.

        // 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 := CreateHBITMAPfromRecordBinaryField(16, idc);

        if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
        begin
          OutputImage.Height := OutputImage.Picture.Bitmap.Height;
          OutputImage.Width := OutputImage.Picture.Bitmap.Width;
          Invalidate;
          Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
        end
        else
        begin
          Application.MessageBox(PChar('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
        end;



        // Make a copy of HBitmap into OutputImage->Picture
    {
         bitmap := CreateHBITMAPfromBinaryNISTField();

            if ( bitmap <> HBitmap(NIL)) then
            begin
               OutputImage.Picture.Bitmap.Handle  := HBitmap(CopyImage(bitmap, IMAGE_BITMAP, 0, 0,LR_COPYRETURNORG));
               OutputImage.Height := OutputImage.Picture.Bitmap.Height;
               OutputImage.Width := OutputImage.Picture.Bitmap.Width;
               Invalidate;
               Application.MessageBox(PByte('Type-16 record text field was exported to file .' + PathDelim + 'output' + PathDelim + 'type16_'+ IntToStr(i)+ '.txt' + LineEnding + 'Type-16 record binary field was exported to file .' + PathDelim + 'output' + PathDelim + 'type16_' + IntToStr(i) + '.wsq' + LineEnding + 'Variable-resolution user-defined testing image was extracted from type 16 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form'), PChar('NIST library'), MB_OK );
            end
            else
            begin
  Application.MessageBox(PByte('Unable to load file'), PChar('NIST library error'), MB_OK or MB_ICONERROR );
            end;
    }

      end;

    end; // for i := 1 to type_16_number_of_records do
  end; // if(CheckIfRecordTypeExists(16) = 1)




  CreateAndInsertButton.Enabled := True;
  ReadAndModifyButton.Enabled := True;
  ReadAndExportButton.Enabled := True;
  ReadSingleFieldButton.Enabled := True;
  DeleteSingleFieldButton.Enabled := True;
  RegisterButton.Enabled := True;
  Screen.Cursor := crDefault;

end;

procedure TMainForm.ReadAndModifyButtonClick(Sender: TObject);
begin

  CreateAndInsertButton.Enabled := false;
  ReadAndModifyButton.Enabled := false;
  ReadAndExportButton.Enabled := false;
  ReadSingleFieldButton.Enabled := false;
  DeleteSingleFieldButton.Enabled := false;
  RegisterButton.Enabled := false;
  Screen.Cursor := crHourGlass;


  traditional_or_xml_format := 0; // traditional format
  //traditional_or_xml_format := 1; // NIEM-conformant XML format
  SetAnsiNistItlVersion(2000, traditional_or_xml_format); // NIEM-conformant XML format


  // Sets input file name as "sample.nist" which located in "input" subdirectory
  filedirectory := program_file_path + 'input' + PathDelim;

  if(traditional_or_xml_format = 0) then
  filename := filedirectory + 'sample.nist'
  else
  filename := filedirectory + 'sample_NIEM_conformant_XML.xml';


  if not FileExists(filename) then
  begin
    if(traditional_or_xml_format = 0) then
    Application.MessageBox(PChar('Error: file .' + PathDelim + 'input' + PathDelim + 'sample.nist does not exist.'), PChar('Error'), MB_OK)
    else
    Application.MessageBox(PChar('Error: file .' + PathDelim + 'input' + PathDelim + 'sample_NIEM_conformant_XML.xml does not exist.'), PChar('Error'), MB_OK);
	
    Exit();
  end;



  // Reads NIST file
  ReadNISTFromFile(PAnsiChar(filename));


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

  // Modifies NIST file, inserts/replaces Type-1 record Date (DAT)
  InsertRecordTxtField(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
  InsertRecordTxtField(1, -1, -1, 'PRY', '2');

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

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

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

  // Modifies NIST file, inserts/replaces Type-1 record Transaction control reference (TCR)
  InsertRecordTxtField(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
  InsertRecordTxtField(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
  InsertRecordTxtField(1, -1, -1, 'NTR', '21.33');

  // Modifies NIST file, inserts/replaces Type-1 record Domain name (DOM)
  InsertRecordTxtField(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
  if(traditional_or_xml_format = 0) then
  InsertRecordTxtField(1, -1, -1, 'GMT', '20080931170316Z')
  else
  InsertRecordTxtField(1, -1, -1, 'GMT', '2008-09-31T17:03:16Z');


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



  // Sets input directory as 'input' subdirectory of the program location
  filedirectory := program_file_path + 'input' + PathDelim;


  // 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 := filedirectory + 'type4_left_thumb.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, 7, PAnsiChar(filename));


  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(4, idc_current, -1, 'FGP1', '6');
  // FGP2 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP2', '255');
  // FGP3 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP3', '255');
  // FGP4 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP4', '255');
  // FGP5 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP5', '255');
  // FGP6 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // '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
  // InsertRecordTxtField(4, idc_current, -1, 'GCA', '1');


  filename := filedirectory + 'type4_right_thumb.wsq';
  idc_current := InsertRecordBinaryFieldFromFile(4, 12, PAnsiChar(filename));
  InsertRecordTxtField(4, idc_current, -1, 'IMP', '3');
  InsertRecordTxtField(4, idc_current, -1, 'FGP1', '1');
  // FGP2 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP2', '255');
  // FGP3 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP3', '255');
  // FGP4 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP4', '255');
  // FGP5 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP5', '255');
  // FGP6 value of '255' was already inserted by default when creating Type-4 record
  // InsertRecordTxtField(4, idc_current, -1, 'FGP6', '255');
  InsertRecordTxtField(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
  // InsertRecordTxtField(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
  // InsertRecordTxtField(4, idc_current, -1, 'VLL', '0');
  // '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
  // InsertRecordTxtField(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 := filedirectory + 'type10_Charles_Luciano_frontal.jpg';


  idc_current := InsertRecordBinaryFieldFromFile(10, 23, PAnsiChar(filename));

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


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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(10, idc_current, -1, 'THPS', '300');

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(10, idc_current, -1, 'TVPS', '300');

  // '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
  // InsertRecordTxtField(10, idc_current, -1, 'CGA', 'JPEGB');

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

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




  filename := filedirectory + 'type10_Charles_Luciano_profile.jpg';

  idc_current := InsertRecordBinaryFieldFromFile(10, 24, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(10, idc_current, -1, 'THPS', '300');

  // Modifies NIST file, inserts/replaces mandatory Type-10 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(10, idc_current, -1, 'TVPS', '300');

  // '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
  // InsertRecordTxtField(10, idc_current, -1, 'CGA', 'JPG');

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

  // Modifies NIST file, inserts/replaces Type-10 record Subject pose (POS)
  InsertRecordTxtField(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 := filedirectory + 'type14_replace_01.wsq';

  idc_current := InsertRecordBinaryFieldFromFile(14, 27, PAnsiChar(filename));

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

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

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

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

  // Modifies NIST file, inserts/replaces mandatory Type-14 record Horizontal pixel scale (THPS)
  InsertRecordTxtField(14, idc_current, -1, 'THPS', '197');

  // Modifies NIST file, inserts/replaces mandatory Type-14 record Vertical pixel scale (TVPS)
  InsertRecordTxtField(14, idc_current, -1, 'TVPS', '197');

  // Modifies NIST file, inserts/replaces mandatory Type-14 record Compression algorithm (CGA)
  // '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
  // InsertRecordTxtField(14, idc_current, -1, 'CGA' ,'WSQ20');

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

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




  // Sets output file name as 'sample_modified.nist' (in "output" subdirectory)
  filedirectory := program_file_path + 'output' + PathDelim;


  if not DirectoryExists(filedirectory) then
  begin
    // Create output directory
    CreateDir(filedirectory);
  end;

  if(traditional_or_xml_format = 0) then
  filename := filedirectory + 'sample_modified.nist'
  else
  filename := filedirectory + 'sample_modified.xml';


  // Saves NIST into the file 'sample_modified.nist' (in "output" subdirectory)
  WriteNISTToFile(PAnsiChar(filename));


  if(traditional_or_xml_format = 0) then
  Application.MessageBox(PChar('NIST file ".' + PathDelim + 'input' + PathDelim + 'sample.nist was read, modified and saved as' + LineEnding + '".' + PathDelim + 'output' + PathDelim + 'sample_modified.nist"' + LineEnding + LineEnding + 'Please use "NIST viewer" to see changes in' + LineEnding + '"sample_modified.nist" file.'), PChar('NIST library'), MB_OK)
  else
  Application.MessageBox(PChar('NIST file ".' + PathDelim + 'input' + PathDelim + 'sample_NIEM_conformant_XML.xml was read, modified and saved as' + LineEnding + '".' + PathDelim + 'output' + PathDelim + 'sample_modified.xml"' + LineEnding + LineEnding + 'Please use "NIST viewer" to see changes in' + LineEnding + '"sample_modified.xml" file.'), PChar('NIST library'), MB_OK);



  CreateAndInsertButton.Enabled := true;
  ReadAndModifyButton.Enabled := true;
  ReadAndExportButton.Enabled := true;
  ReadSingleFieldButton.Enabled := true;
  DeleteSingleFieldButton.Enabled := true;
  RegisterButton.Enabled := true;
  Screen.Cursor := crDefault;

end;

procedure TMainForm.ReadSingleFieldButtonClick(Sender: TObject);
begin

  if not open_dialog.Execute() then
  begin
    exit;
  end;

  bitmap := HBitmap(nil);

  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.
  // ReadNISTFromFile(PByte(open_dialog.FileName));


  // Instead function ReadNISTFromFile you can use function ReadNISTFromMemory (the code bellow)
  // ==========================
  iFileHandle := FileOpen(open_dialog.FileName, fmOpenRead);
  iFileLength := FileSeek(iFileHandle, 0, 2);
  FileSeek(iFileHandle, 0, 0);
  byte_array := PByte(AllocMem(iFileLength + 1));
  size_of_byte_array := FileRead(iFileHandle, byte_array^, iFileLength);
  FileClose(iFileHandle);

  // 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.
  ReadNISTFromMemory(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 <> PByte(nil)) then
  begin
    FreeMem(byte_array);
    byte_array := PByte(nil);
  end;
  // ==========================



  if( LowerCase(ExtractFileExt(open_dialog.FileName)) = '.xml' ) then
  traditional_or_xml_format := 1  // NIEM-conformant XML format
  else
  traditional_or_xml_format := 0; // traditional format



  if (CheckIfRecordTypeExists(1) = 1) then
  begin

    output_message := 'Type-1 record field values were read in cycle using field number' + LineEnding + LineEnding;

    for i := 1 to 15 do
    begin
      output_message := output_message + 'Type-1 record ';
      // Reads Type-1 record i Field Description
      nist_txt_field := ReadRecordTxtFieldDescription(1, -1, i, '');
      output_message := output_message + nist_txt_field;
      output_message := output_message + ' (';
      // Reads Type-1 record i Field Name
      nist_txt_field := ReadRecordTxtFieldName(1, -1, i);
      output_message := output_message + nist_txt_field;
      output_message := output_message + ') = ';
      // Reads Type-1 record i Field Value
      nist_txt_field := ReadRecordTxtField(1, -1, i, '');
      output_message := output_message + nist_txt_field;
      output_message := output_message + LineEnding;
    end;
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);



    output_message := 'Type-1 record field values were read using field names' + LineEnding + LineEnding;

    if(traditional_or_xml_format = 0) then  // traditional format
    begin
    // Reads Type-1 record Logical record length (LEN)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'LEN');
    output_message := output_message + 'Type-1 record Logical record length (LEN) = ';
    output_message := output_message + nist_txt_field;
    end;

    // Reads Type-1 record Version number (VER) of the standard implemented by the software or system creating the file
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'VER');
    output_message := output_message + LineEnding + 'Type-1 record Version number (VER) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record File content (CNT)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'CNT');
    output_message := output_message + LineEnding + 'Type-1 record File content (CNT) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Type of transaction (TOT)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'TOT');
    output_message := output_message + LineEnding + 'Type-1 record Type of transaction (TOT) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Date (DAT)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'DAT');
    output_message := output_message + LineEnding + 'Type-1 record Date (DAT) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Priority RY)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'PRY');
    output_message := output_message + LineEnding + 'Type-1 record Priority RY) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Destination agency identifier (DAI)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'DAI');
    output_message := output_message + LineEnding + 'Type-1 record Destination agency identifier (DAI) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Originating agency identifier (ORI)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'ORI');
    output_message := output_message + LineEnding + 'Type-1 record Originating agency identifier (ORI) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Transaction control number (TCN)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'TCN');
    output_message := output_message + LineEnding + 'Type-1 record Transaction control number (TCN) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Transaction control reference (TCR)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'TCR');
    output_message := output_message + LineEnding + 'Type-1 record Transaction control reference (TCR) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Native scanning resolution(NSR)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'NSR');
    output_message := output_message + LineEnding + 'Type-1 record Native scanning resolution (NSR) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Nominal transmitting resolution (NTR)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'NTR');
    output_message := output_message + LineEnding + 'Type-1 record Nominal transmitting resolution (NTR) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Domain name (DOM)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'DOM');
    output_message := output_message + LineEnding + 'Type-1 record Domain name (DOM) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Greenwich mean time (GMT)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'GMT');
    output_message := output_message + LineEnding + 'Type-1 record Greenwich mean time (GMT) = ';
    output_message := output_message + nist_txt_field;

    // Reads Type-1 record Directory of character sets (DCS)
    nist_txt_field := ReadRecordTxtField(1, -1, -1, 'DCS');
    output_message := output_message + LineEnding + 'Type-1 record Directory of character sets (DCS) = ';
    output_message := output_message + nist_txt_field;
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

  end; // if(CheckIfRecordTypeExists(1) = 1)


  if (CheckIfRecordTypeExists(2) = 1) then
  begin

    type_2_number_of_records := ReadNumberOfRecords(2);
    output_message := 'Type-2 number of records = ' + IntToStr(type_2_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

    for i := 1 to type_2_number_of_records do
    begin
      output_message := '';
	  
      idc := ReadIDCofRecord(2, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-2 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(2, idc, 1, '');
      output_message := output_message + 'Type-2 record Logical record length (LEN) = ';
      output_message := output_message + nist_txt_field;
      end;

      // Reads Type-2 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(2, idc, 2, '');
      output_message := output_message + LineEnding + 'Type-2 record Image designation character (IDC) = ';
      output_message := output_message + nist_txt_field;

      // Reads Type-2 record User-defined field #30
      nist_txt_field := ReadRecordTxtField(2, idc, 30, '');
      output_message := output_message + LineEnding + 'Type-2 record User-defined field #30 = ';
      output_message := output_message + nist_txt_field;

      // Reads Type-2 record User-defined field #31
      nist_txt_field := ReadRecordTxtField(2, idc, 31, '');
      output_message := output_message + LineEnding + 'Type-2 record User-defined field #31 = ';
      output_message := output_message + nist_txt_field;

      // Reads Type-2 record User-defined field #32
      nist_txt_field := ReadRecordTxtField(2, idc, 32, '');
      output_message := output_message + LineEnding + 'Type-2 record User-defined field #32 = ';
      output_message := output_message + nist_txt_field;
      Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

    end; // for i := 1 to type_2_number_of_records do

  end; // if(CheckIfRecordTypeExists(2) = 1)



  if (CheckIfRecordTypeExists(4) = 1) then
  begin

    type_4_number_of_records := ReadNumberOfRecords(4);
    output_message := 'Type-4 number of records = ' + IntToStr(type_4_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('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 i := 1 to type_4_number_of_records do
    begin
      output_message := '';
	  
      idc := ReadIDCofRecord(4, i);

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

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-4 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'LEN');
      output_message := output_message + 'Type-4 (' + IntToStr(idc) +') record Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-4 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-4 record Impression type (IMP)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'IMP');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Impression type (IMP) = ' + nist_txt_field;

      // Reads Type-4 record Finger position (FGP)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Finger position (FGP) = ' + nist_txt_field;

      // Reads Type-4 record Known or most probable Finger position (FGP1)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP1');

      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Known or most probable Finger position (FGP1) = ' +  nist_txt_field;

      // Reads Type-4 record Second possible Finger position (FGP2)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP2');

      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Second possible Finger position (FGP2) = ' + nist_txt_field;

      // Reads Type-4 record Third possible Finger position (FGP3)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP3');

      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Third possible Finger position (FGP3) = ' + nist_txt_field;

      // Reads Type-4 record Fourth possible Finger position (FGP4)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP4');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Fourth possible Finger position (FGP4) = ' + nist_txt_field;

      // Reads Type-4 record Fifth possible Finger position (FGP5)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP5');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Fifth possible Finger position (FGP5) = ' + nist_txt_field;

      // Reads Type-4 record Sixth possible Finger position (FGP6)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'FGP6');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Sixth possible Finger position (FGP6) = ' + nist_txt_field;

      // Reads Type-4 record Image scanning resolution (ISR)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'ISR');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Image scanning resolution (ISR) = ' + nist_txt_field;

      // Reads Type-4 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-4 record Vertical line length (VLL)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Vertical line length (VLL) = ' + nist_txt_field;

      // Reads Type-4 record Grayscale compression algorithm (GCA)
      nist_txt_field := ReadRecordTxtField(4, idc, -1, 'GCA');
      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(idc) + ') record Grayscale compression algorithm (GCA) = ' + nist_txt_field;

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

      output_message := output_message + LineEnding + 'Type-4 (' + IntToStr(i) + ') record Size of binary field = ' + IntToStr(size);


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


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(4, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'High-resolution grayscale fingerprint image was extracted from type 4 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end; // for i := 1 to type_4_number_of_records do

  end; // if(CheckIfRecordTypeExists(4) = 1)



  if (CheckIfRecordTypeExists(7) = 1) then
  begin
    type_7_number_of_records := ReadNumberOfRecords(7);
    output_message := 'Type-7 number of records = ' + IntToStr(type_7_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);


    // Reads NIST file and shows facial and SMT images on the screen.
    for i := 1 to type_7_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(7, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-7 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-7 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-7 record Image type (IMT)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'IMT');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Image type (IMT) = ' + nist_txt_field;

      // Reads Type-7 record Image description (IMD)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'IMD');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Image description (IMD) = ' + nist_txt_field;

      // Reads Type-7 record Pattern classification (PCN)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'PCN');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Pattern classification (PCN) = ' + nist_txt_field;

      // Reads Type-7 record Image capture resolution (IMR)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'IMR');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Image capture resolution (IMR) = ' + nist_txt_field;

      // Reads Type-7 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-7 record Horizontal line length (VLL)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Horizontal line length (VLL) = ' + nist_txt_field;

      // Reads Type-7 record Gray-scale compression algorithm (GCA)
      nist_txt_field := ReadRecordTxtField(7, idc, -1, 'GCA');
      output_message := output_message + LineEnding + 'Type-7 (' + IntToStr(idc) + ') Gray-scale compression algorithm (GCA) = ' + nist_txt_field;


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(7, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'User-defined image was extracted from type 7 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_7_number_of_records do

  end;// if(CheckIfRecordTypeExists(7) = 1)




  if (CheckIfRecordTypeExists(8) = 1) then
  begin
    type_8_number_of_records := ReadNumberOfRecords(8);
    output_message := 'Type-8 number of records = ' + IntToStr(type_8_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);


    // Reads NIST file and shows facial and SMT images on the screen.
    for i := 1 to type_8_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(8, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-8 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-8 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-8 record Signature type (SIG)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'SIG');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Signature type (SIG) = ' + nist_txt_field;

      // Reads Type-8 record Signature representation type (SRT)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'SRT');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Signature representation type (SRT) = ' + nist_txt_field;

      // Reads Type-8 record Image scanning resolution (ISR)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'ISR');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Image scanning resolution (ISR) = ' + nist_txt_field;

      // Reads Type-8 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-8 record Vertical line length (VLL)
      nist_txt_field := ReadRecordTxtField(8, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-8 (' + IntToStr(idc) + ') Vertical line length (VLL) = ' + nist_txt_field;


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(8, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Signature image was extracted from type 8 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_8_number_of_records do

  end;// if(CheckIfRecordTypeExists(8) = 1)




  if (CheckIfRecordTypeExists(9) = 1) then
  begin

    type_9_number_of_records := ReadNumberOfRecords(9);
    output_message := 'Type-9 number of records = ' + IntToStr(type_9_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);


    // Reads NIST file and shows minutiae data images on the screen.
    for i := 1 to type_9_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(9, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-9 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') record Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-9 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-9 record Impression type (IMP)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'IMP');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Impression type (IMP) = ' + nist_txt_field;

      // Reads Type-9 record Minutiae format (FMT)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'FMT');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Minutiae format (FMT) = ' + nist_txt_field;

      if(nist_txt_field = 'S') then
      begin

      // Reads Type-9 record Originating fingerprint reading system (OFR)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'OFR');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Originating fingerprint reading system (OFR) = ' + nist_txt_field;

      // Reads Type-9 record Finger position (FGP)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'FGP');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Finger position (FGP) = ' + nist_txt_field;

      // Reads Type-9 record Fingerprint pattern classification (FPC)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'FPC');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Fingerprint pattern classification (FPC) = ' + nist_txt_field;

      // Reads Type-9 record Core position (CRP)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'CRP');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Core position (CRP) = ' + nist_txt_field;

      // Reads Type-9 record Delta(s) position (DLT)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'DLT');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Delta(s) position (DLT) = ' + nist_txt_field;

      // Reads Type-9 record Number of minutiae (MIN)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'MIN');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Number of minutiae (MIN) = ' + nist_txt_field;

      // Reads Type-9 record Number of minutiae (RDG)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'RDG');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Number of minutiae (RDG) = ' + nist_txt_field;

      // Reads Type-9 record Number of minutiae (MRC)
      nist_txt_field := ReadRecordTxtField(9, idc, -1, 'MRC');
      output_message := output_message + LineEnding + 'Type-9 (' + IntToStr(idc) + ') Number of minutiae (MRC) = ' + nist_txt_field;
      // Application->MessageBox( output_message, 'NIST library', MB_OK );

      end; // if(nist_txt_field = 'S') then


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(9, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Minutiae data was extracted from type 9 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_9_number_of_records do

  end;// if(CheckIfRecordTypeExists(9) = 1)



  if (CheckIfRecordTypeExists(10) = 1) then
  begin
    type_10_number_of_records := ReadNumberOfRecords(10);
    output_message := 'Type-10 number of records = ' + IntToStr(type_10_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);


    // Reads NIST file and shows facial and SMT images on the screen.
    for i := 1 to type_10_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(10, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-10 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-10 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-10 record Image type (IMT)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'IMT');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Image type (IMT) = ' + nist_txt_field;

      // Reads Type-10 record Source agency / ORI (SRC)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SRC');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Source agency / ORI (SRC) = ' + nist_txt_field;

      // Reads Type-10 record Photo date (PHD)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'PHD');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Photo date (PHD)  = ' + nist_txt_field;

      // Reads Type-10 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-10 record Vertical line length (VLL)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Vertical line length (VLL) = ' + nist_txt_field;

      // Reads Type-10 record Scale units (SLC)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SLC');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Scale units (SLC) = ' + nist_txt_field;

      // Reads Type-10 record Horizontal pixel scale (THPS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'THPS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Horizontal pixel scale (THPS) = ' + nist_txt_field;

      // Reads Type-10 record Vertical pixel scale (TVPS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'TVPS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Vertical pixel scale (TVPS) = ' + nist_txt_field;

      // Reads Type-10 record Compression algorithm (CGA)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'CGA');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Compression algorithm (CGA) = ' + nist_txt_field;

      // Reads Type-10 record Colorspace (CSP)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'CSP');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Colorspace (CSP) = ' + nist_txt_field;

      // Reads Type-10 record Subject acquisition profile (SAP)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SAP');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject acquisition profile (SAP) = ' + nist_txt_field;


      // Reads Type-10 record Subject pose (POS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'POS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject pose (POS) = ' + nist_txt_field;

      // Reads Type-10 record Pose offset angle (POA)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'POA');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Pose offset angle (POA) = ' + nist_txt_field;

      // Reads Type-10 record Photo description (PXS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'PXS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Photo description (PXS) = ' + nist_txt_field;

      // Reads Type-10 record Photo acquisition source (PAS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'PAS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Photo acquisition source (PAS) = ' + nist_txt_field;

      // Reads Type-10 record Subject quality score (SQS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SQS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject quality score (SQS) = ' + nist_txt_field;

      // Reads Type-10 record Subject pose angles (SPA)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SPA');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject pose angles (SPA) = ' + nist_txt_field;

      // Reads Type-10 record Subject facial description (SXS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SXS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject facial description (SXS) = ' + nist_txt_field;

      // Reads Type-10 record Subject eye color (SEC)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SEC');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject eye color (SEC) = ' + nist_txt_field;

      // Reads Type-10 record Subject hair color (SHC)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SHC');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Subject hair color (SHC) = ' + nist_txt_field;

      // Reads Type-10 record Facial feature points (FFP)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'FFP');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Facial feature points (FFP) = ' + nist_txt_field;

      // Reads Type-10 record Device monitoring mode (DMM)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'DMM');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Device monitoring mode (DMM) = ' + nist_txt_field;

      // Reads Type-10 record NCIC designation code (SMT)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SMT');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') NCIC designation code (SMT) = ' + nist_txt_field;

      // Reads Type-10 record SMT size (SMS)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SMS');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') SMT size (SMS) = ' + nist_txt_field;

      // Reads Type-10 record SMT descriptors (SMD)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'SMD');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') SMT descriptors (SMD) = ' + nist_txt_field;

      // Reads Type-10 record Color (COL)
      nist_txt_field := ReadRecordTxtField(10, idc, -1, 'COL');
      output_message := output_message + LineEnding + 'Type-10 (' + IntToStr(idc) + ') Color (COL) = ' + nist_txt_field;
      // Application->MessageBox( output_message, 'NIST library', MB_OK );


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(10, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Facial & SMT image was extracted from type 10 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_10_number_of_records do

  end;// if(CheckIfRecordTypeExists(10) = 1)



  if (CheckIfRecordTypeExists(13) = 1) then
  begin
    type_13_number_of_records := ReadNumberOfRecords(13);
    output_message := 'Type-13 number of records = ' + IntToStr(type_13_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

    // Reads NIST file and shows latent images on the screen.
    for i := 1 to type_13_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(13, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-13 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-13 record Image Designation Character (IDC)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Image Designation Character (IDC) = ' + nist_txt_field;

      // Reads Type-13 record Impression Type (IMP)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'IMP');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Impression Type (IMP) = ' + nist_txt_field;

      // Reads Type-13 record Source agency / ORI (SRC)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'SRC');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Source agency / ORI (SRC) = ' + nist_txt_field;

      // Reads Type-13 record Latent capture date (LCD)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'LCD');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Latent capture date (LCD) = ' + nist_txt_field;

      // Reads Type-13 record Latent capture date (HLL)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Latent capture date (HLL) = ' + nist_txt_field;

      // Reads Type-13 record Latent capture date (VLL)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Latent capture date (VLL) = ' + nist_txt_field;

      // Reads Type-13 record Scale units (SLC)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'SLC');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Scale units (SLC) = ' + nist_txt_field;

      // Reads Type-13 record Horizontal pixel scale (THPS)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'THPS');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Horizontal pixel scale (THPS) = ' + nist_txt_field;

      // Reads Type-13 record Vertical pixel scale (TVPS)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'TVPS');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Vertical pixel scale (TVPS) = ' + nist_txt_field;

      // Reads Type-13 record Compression algorithm (CGA)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'CGA');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Compression algorithm (CGA) = ' + nist_txt_field;

      // Reads Type-13 record Bits per pixel (BPX)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'BPX');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Bits per pixel (BPX) = ' + nist_txt_field;

      // Reads Type-13 record Finger / palm position (FGP)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'FGP');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Finger / palm position (FGP) = ' + nist_txt_field;

      // Reads Type-13 record Search position descriptors (SPD)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'SPD');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Search position descriptors (SPD) = ' + nist_txt_field;

      // Reads Type-13 record Print position coordinates (PPC)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'PPC');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Print position coordinates (PPC) = ' + nist_txt_field;

      // Reads Type-13 record Scanned horizontal pixel scale (SHPS)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'SHPS');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Scanned horizontal pixel scale (SHPS) = ' + nist_txt_field;

      // Reads Type-13 record Scanned vertical pixel scale (SVPS)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'SVPS');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Scanned vertical pixel scale (SVPS) = ' + nist_txt_field;

      // Reads Type-13 record Comment (COM)
      nist_txt_field := ReadRecordTxtField(13, idc, -1, 'COM');
      output_message := output_message + LineEnding + 'Type-13 (' + IntToStr(idc) + ') Comment (COM) = ' + nist_txt_field;
      // Application->MessageBox( output_message, 'NIST library', MB_OK );


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(13, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message :=  output_message + LineEnding + 'Variable-resolution latent image was extracted from type 13 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_13_number_of_records do

  end;// if(CheckIfRecordTypeExists(13) = 1)


  if (CheckIfRecordTypeExists(14) = 1) then
  begin
    type_14_number_of_records := ReadNumberOfRecords(14);
    output_message := 'Type-14 number of records = ' + IntToStr(type_14_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);


    // Reads NIST file and shows tenprint images images on the screen.
    for i := 1 to type_14_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(14, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-14 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-14 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-14 record Impression type (IMP)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'IMP');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Impression type (IMP) = ' + nist_txt_field;

      // Reads Type-14 record Source agency / ORI (SRC)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SRC');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Source agency / ORI (SRC) = ' + nist_txt_field;

      // Reads Type-14 record Tenprint capture date (TCD)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'TCD');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Tenprint capture date (TCD) = ' + nist_txt_field;

      // Reads Type-14 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-14 record Vertical line length (VLL)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Vertical line length (VLL) = ' + nist_txt_field;

      // Reads Type-14 record Scale units (SLC)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SLC');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Scale units (SLC) = ' + nist_txt_field;

      // Reads Type-14 record Horizontal pixel scale (THPS)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'THPS');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Horizontal pixel scale (THPS) = ' + nist_txt_field;

      // Reads Type-14 record Vertical pixel scale (TVPS)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'TVPS');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Vertical pixel scale (TVPS) = ' + nist_txt_field;

      // Reads Type-14 record Compression algorithm (CGA)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'CGA');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Compression algorithm (CGA) = ' + nist_txt_field;

      // Reads Type-14 record Bits per pixel (BPX)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'BPX');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Bits per pixel (BPX) = ' + nist_txt_field;

      // Reads Type-14 record Finger position (FGP)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'FGP');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Finger position (FGP) = ' + nist_txt_field;

      // Reads Type-14 record Print position descriptors (PPD)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'PPD');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Print position descriptors (PPD) = ' + nist_txt_field;

      // Reads Type-14 record Print position coordinates (PPC)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'PPC');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Print position coordinates (PPC) = ' + nist_txt_field;

      // Reads Type-14 record Scanned horizontal pixel scale (SHPS)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SHPS');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Scanned horizontal pixel scale (SHPS) = ' + nist_txt_field;

      // Reads Type-14 record Scanned vertical pixel scale (SVPS)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SVPS');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Scanned vertical pixel scale (SVPS) = ' + nist_txt_field;

      // Reads Type-14 record Amputated or bandaged (AMP)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'AMP');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Amputated or bandaged (AMP) = ' + nist_txt_field;

      // Reads Type-14 record Comment (COM)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'COM');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Comment (COM) = ' + nist_txt_field;

      // Reads Type-14 record Finger segment position(s) (SEG)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SEG');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Finger segment position(s) (SEG) = ' + nist_txt_field;

      // Reads Type-14 record NIST quality metric (NQM)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'NQM');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') NIST quality metric (NQM) = ' + nist_txt_field;

      // Reads Type-14 record Segmentation quality metric (SQM)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'SQM');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Segmentation quality metric (SQM) = ' + nist_txt_field;

      // Reads Type-14 record Fingerprint quality metric (FQM)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'FQM');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Fingerprint quality metric (FQM) = ' + nist_txt_field;

      // Reads Type-14 record Alternate finger segment position(s) (ASEG)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'ASEG');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Alternate finger segment position(s) (ASEG) = ' + nist_txt_field;

      // Reads Type-14 record Device monitoring mode (DMM)
      nist_txt_field := ReadRecordTxtField(14, idc, -1, 'DMM');
      output_message := output_message + LineEnding + 'Type-14 (' + IntToStr(idc) + ') Device monitoring mode (DMM) = ' + nist_txt_field;
      // Application->MessageBox( output_message, 'NIST library', MB_OK );



      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(14, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Variable-resolution fingerprint image was extracted from type 14 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_14_number_of_records do

  end;// if(CheckIfRecordTypeExists(14) = 1)



  if (CheckIfRecordTypeExists(15) = 1) then
  begin
    type_15_number_of_records := ReadNumberOfRecords(15);
    output_message := 'Type-15 number of records = ' + IntToStr(type_15_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

    // Reads NIST file and shows fingerprint images on the screen.
    for i := 1 to type_15_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(15, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-15 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-15 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-15 record Impression type (IMP)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'IMP');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Impression type (IMP) = ' + nist_txt_field;

      // Reads Type-15 record Source agency/ORI (SRC)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'SRC');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Source agency/ORI (SRC) = ' + nist_txt_field;

      // Reads Type-15 record Palmprint capture date (PCD)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'PCD');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Palmprint capture date (PCD) = ' + nist_txt_field;

      // Reads Type-15 record Horizontal line length (HLL)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Horizontal line length (HLL) = ' + nist_txt_field;

      // Reads Type-15 record Vertical line length (VLL)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Vertical line length (VLL) = ' + nist_txt_field;

      // Reads Type-15 record Scale units (SLC)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'SLC');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Scale units (SLC) = ' + nist_txt_field;

      // Reads Type-15 record Horizontal pixel scale (THPS)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'THPS');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Horizontal pixel scale (THPS) = ' + nist_txt_field;

      // Reads Type-15 record Vertical pixel scale (TVPS)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'TVPS');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Vertical pixel scale (TVPS) = ' + nist_txt_field;

      // Reads Type-15 record Compression algorithm (CGA)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'CGA');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Compression algorithm (CGA) = ' + nist_txt_field;

      // Reads Type-15 record Bits per pixel (BPX)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'BPX');
      output_message := output_message + LineEnding + 'Type-15 (' +  IntToStr(idc) + ') Bits per pixel (BPX) = ' + nist_txt_field;

      // Reads Type-15 record Palmprint position (PLP)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'PLP');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Palmprint position (PLP) = ' + nist_txt_field;

      // Reads Type-15 record Scanned horizontal pixel scale (SHPS)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'SHPS');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Scanned horizontal pixel scale (SHPS) = ' + nist_txt_field;

      // Reads Type-15 record Scanned vertical pixel scale (SVPS)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'SVPS');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Scanned vertical pixel scale (SVPS) = ' + nist_txt_field;

      // Reads Type-15 record Comment (COM)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'COM');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Comment (COM) = ' + nist_txt_field;

      // Reads Type-15 record Palmprint quality metric (PQM)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'PQM');
      output_message := output_message + LineEnding + 'Type-15 (' + IntToStr(idc) + ') Palmprint quality metric (PQM) = ' + nist_txt_field;

      // Reads Type-15 record Device monitoring mode (DMM)
      nist_txt_field := ReadRecordTxtField(15, idc, -1, 'DMM');
      output_message := output_message + LineEnding + 'Type-15 (' +
        IntToStr(idc) + ') Device monitoring mode (DMM) = ' + nist_txt_field;
      // Application->MessageBox( output_message, 'NIST library', MB_OK );


      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(15, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Variable-resolution palmprint image was extracted from type 15 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_15_number_of_records do

  end;// if(CheckIfRecordTypeExists(15) = 1)


  if (CheckIfRecordTypeExists(16) = 1) then
  begin
    type_16_number_of_records := ReadNumberOfRecords(16);
    output_message := 'Type-16 number of records = ' + IntToStr(type_16_number_of_records);
    Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);

    // Reads NIST file and shows fingerprint images on the screen.
    for i := 1 to type_16_number_of_records do
    begin
      output_message := '';

      idc := ReadIDCofRecord(16, i);

      if(traditional_or_xml_format = 0) then  // traditional format
      begin
      // Reads Type-16 record Logical record length (LEN)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'LEN');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Logical record length (LEN) = ' + nist_txt_field;
      end;

      // Reads Type-16 record Image designation character (IDC)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'IDC');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Image designation character (IDC) = ' + nist_txt_field;

      // Reads Type-16 record User-Defined Image (UDI)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'UDI');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') User-Defined Image (UDI) = ' + nist_txt_field;

      // Reads Type-16 record Source Agency / ORI (SRC)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'SRC');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Source Agency / ORI (SRC) = ' + nist_txt_field;

      // Reads Type-16 record User-Defined Testing Date (UTD)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'UTD');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') User-Defined Testing Date (UTD) = ' + nist_txt_field;

      // Reads Type-16 record Horizontal Line Length (HLL)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'HLL');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Horizontal Line Length (HLL) = ' + nist_txt_field;

      // Reads Type-16 record Vertical Line Length (VLL)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'VLL');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Vertical Line Length (VLL) = ' + nist_txt_field;

      // Reads Type-16 record Scale Units (SLC)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'SLC');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Scale Units (SLC) = ' + nist_txt_field;

      // Reads Type-16 record Horizontal Pixel Scale (THPS)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'THPS');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Horizontal Pixel Scale (THPS) = ' + nist_txt_field;

      // Reads Type-16 record Vertical Pixel Scale (TVPS)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'TVPS');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Vertical Pixel Scale (TVPS) = ' + nist_txt_field;

      // Reads Type-16 record Compression Algorithm (CGA)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'CGA');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Compression Algorithm (CGA) = ' + nist_txt_field;

      // Reads Type-16 record Bits Per Pixel (BPX)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'BPX');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Bits Per Pixel (BPX) = ' + nist_txt_field;

      // Reads Type-16 record Color Space (CSP)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'CSP');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Color Space (CSP) = ' + nist_txt_field;

      // Reads Type-16 record Scanned Horizontal Pixel Scale (SHPS)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'SHPS');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Horizontal Pixel Scale (SHPS) = ' + nist_txt_field;

      // Reads Type-16 record Scanned Vertical Pixel Scale (SVPS)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'SVPS');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Scanned Vertical Pixel Scale (SVPS) = ' + nist_txt_field;

      // Reads Type-16 record Comment (COM)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'COM');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Comment (COM) = ' + nist_txt_field;

      // Reads Type-16 record User-Defined Testing Image Quality Score (UQS)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'UQS');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') User-Defined Testing Image Quality Score (UQS) = ' + nist_txt_field;

      // Reads Type-16 record Device Monitoring Mode (DMM)
      nist_txt_field := ReadRecordTxtField(16, idc, -1, 'DMM');
      output_message := output_message + LineEnding + 'Type-16 (' + IntToStr(idc) + ') Device Monitoring Mode (DMM) = ' + nist_txt_field;


      // Application->MessageBox( output_message, 'NIST library', MB_OK );



      // Converts NIST file binary field contents into HBITMAP image.
      // Returns image in HBITMAP format if successful, returns NULL otherwise.
      OutputImage.Picture.Bitmap.Handle := CreateHBITMAPfromRecordBinaryField(16, idc);

      if (OutputImage.Picture.Bitmap.Handle <> HBitmap(nil)) then
      begin
        OutputImage.Height := OutputImage.Picture.Bitmap.Height;
        OutputImage.Width := OutputImage.Picture.Bitmap.Width;
        Invalidate;
        output_message := output_message + LineEnding + 'Variable-resolution user-defined testing image was extracted from type 16 record binary field' + LineEnding + 'of NIST file and converted into HBITMAP for showing on form.';
        Application.MessageBox(PChar(output_message), PChar('NIST library'), MB_OK);
      end
      else
      begin
        Application.MessageBox(PChar('Error: HBitmap = NULL'), PChar('NIST library error'), MB_OK or MB_ICONERROR);
      end;

    end;// for i := 1 to type_16_number_of_records do

  end;// if(CheckIfRecordTypeExists(16) = 1)




  CreateAndInsertButton.Enabled := true;
  ReadAndModifyButton.Enabled := true;
  ReadAndExportButton.Enabled := true;
  ReadSingleFieldButton.Enabled := true;
  DeleteSingleFieldButton.Enabled := true;
  RegisterButton.Enabled := true;
  Screen.Cursor := crDefault;

end;

procedure TMainForm.RegisterButtonClick(Sender: TObject);
begin

  RegisterNIST();

end;



end.

