//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TFormMain *FormMain;
//---------------------------------------------------------------------------
__fastcall TFormMain::TFormMain(TComponent* Owner): TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
  BarcodeDecoder = new TBarcodeDecoder();
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
  delete BarcodeDecoder;
}
//---------------------------------------------------------------------------
String __fastcall BytesToStr(TBytes Bytes)
{
  String Result = "";
  for (int I = 0; I < Bytes.Length; ++I)
  {
    if (I != 0)
      Result += " ";
    Result += IntToHex(Bytes[I], 2);
  }
  return Result;
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::ButtonScanClick(TObject *Sender)
{
  Memo->Lines->Clear();
  TDecodeResults Barcodes = BarcodeDecoder->Decode(ImageControl->Bitmap);
  for (int I = 0; I < Barcodes.Length; ++I)
  {
    Memo->Lines->Append("Barcode " + IntToStr(I + 1));
    Memo->Lines->Append("  Format: " + IntToStr((int)Barcodes[I].Format));
    Memo->Lines->Append("  Format name: " + Barcodes[I].FormatName);
    Memo->Lines->Append("  Text: " + Barcodes[I].Text);
    Memo->Lines->Append("  Bytes: " + BytesToStr(Barcodes[I].Bytes));
    Memo->Lines->Append("  Timestamp: " + IntToStr(Barcodes[I].Timestamp));
    Memo->Lines->Append("  Bit count: " + IntToStr(Barcodes[I].BitCount));
    Memo->Lines->Append("  Country: " + Barcodes[I].Country);
    Memo->Lines->Append("  Correction level: " + Barcodes[I].CorrectionLevel);
    Memo->Lines->Append("  Extension: " + Barcodes[I].Extension);
    Memo->Lines->Append("  Price: " + Barcodes[I].Price);
    Memo->Lines->Append("  Symbology identifier: " + Barcodes[I].SymbologyIdentifier);

    auto ByteSegments = Barcodes[I].ByteSegments;
    for (int J = 0; J < ByteSegments.Length; ++J)
      Memo->Lines->Append("  Byte segment " + IntToStr(J + 1) + ": " + BytesToStr(ByteSegments[J]));

    auto Points = Barcodes[I].Points;
    for (int J = 0; J < Points.Length; ++J)
      Memo->Lines->Append("  Point " + IntToStr(J + 1) + ": " + FloatToStr(Points[J].X) + "," + FloatToStr(Points[J].Y));
  }
}
//---------------------------------------------------------------------------

