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

#include <vcl.h>
#pragma hdrstop

#include "AllFram_.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "VidGrab"
#pragma resource "*.dfm"
TForm1 *Form1;
int FrameCount = 0;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   VideoGrabber1->BurstCount = 0;
   VideoGrabber1->BurstMode = True;
   VideoGrabber1->CaptureFrameTo (fc_TBitmap, "");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::VideoGrabber1FrameCaptureCompleted(TObject *Sender,
      Pointer MemoryBitmap, TFrameCaptureDest DestType,
      AnsiString FileName, bool Success)
{
   Graphics::TBitmap *Captured_Bitmap; // redeclaration caused by the ambiguity between windows::Bitmap and Graphics::Bitmap

   (void*) Captured_Bitmap = MemoryBitmap;

   Image1->Width = Captured_Bitmap->Width;
   Image1->Height = Captured_Bitmap->Height;
   Image1->Picture->Assign (Captured_Bitmap);
   FrameCount ++;
   Edit1->Text = "  " + IntToStr (FrameCount);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
   VideoGrabber1->BurstMode = False;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::VideoGrabber1ChangeVideoDevice(TObject *Sender)
{
   ComboBox1->Items->Text = VideoGrabber1->VideoDevices;
   ComboBox1->ItemIndex = VideoGrabber1->VideoDevice;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   ComboBox1->Items->Text = VideoGrabber1->VideoDevices;
   ComboBox1->ItemIndex = VideoGrabber1->VideoDevice;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit1Click(TObject *Sender)
{
   Close();        
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
   VideoGrabber1->VideoDevice = ComboBox1->ItemIndex;
   VideoGrabber1->BurstCount = 0;
   VideoGrabber1->BurstMode = True;
   VideoGrabber1->CaptureFrameTo (fc_TBitmap, "");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::VideoGrabber1DeviceArrival(TObject *Sender)
{
   ComboBox1->Items->Text = VideoGrabber1->VideoDevices;
}
//---------------------------------------------------------------------------
