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

#include <vcl.h>
#pragma hdrstop

#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FlashPlayerControl"
#pragma resource "*.dfm"
#pragma resource "res\\movie.res"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ButtonSiteClick(TObject *Sender)
{
  ShellExecute(0, NULL, "http://www.flashplayercontrol.com/delphi/", NULL, NULL, SW_SHOW);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ButtonOrderClick(TObject *Sender)
{
  ShellExecute(0, NULL, "http://www.flashplayercontrol.com/delphi/order.html", NULL, NULL, SW_SHOW);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  if (!Flashplayercontrol::IsFlashInstalled())
  {
    ShowMessage("The application needs Flash\nFlash is not installed");
    Application->Terminate();
  }

  TFlashVersion UsingFlashVersion;
  Flashplayercontrol::GetUsingFlashVersion(UsingFlashVersion);

  // Check high version component, i.e. flash version must be at least 8.*.*.*
  if (UsingFlashVersion.version[3] < 8)
  {
    char Message[1024];
    wsprintf(Message, "The Sample needs Flash 8 or higher\nCurrent version of Flash: %d.%d.%d.%d", UsingFlashVersion.version[3], UsingFlashVersion.version[2], UsingFlashVersion.version[1], UsingFlashVersion.version[0]);
    ShowMessage(Message);
  }

  TResourceStream* ResourceStream = new TResourceStream(0, "ExternalInterface", "FLASH");
  FlashPlayerControl1->PutMovieFromStream(ResourceStream);
  TransparentFlashPlayerControl1->PutMovieFromStream(ResourceStream);
  delete ResourceStream;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FlashPlayerControl1FlashCall(TObject *ASender,
      const WideString request)
{
   FlashPlayerControl1->SetReturnValue("<string>Current time is: " + TimeToStr(Time()) + "\r\nThis info is returned by TMainForm.FlashPlayerControl1FlashCall()</string>");
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::TransparentFlashPlayerControl1FlashCall(
      TObject *ASender, const WideString request)
{
   TransparentFlashPlayerControl1->SetReturnValue("<string>Current time is: " + TimeToStr(Time()) + "\r\nThis info is returned by TMainForm.TransparentFlashPlayerControl1FlashCall()</string>");
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ButtonCallActionScriptFunction1Click(
      TObject *Sender)
{
   WideString Response = FlashPlayerControl1->CallFunction("<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for TFlashPlayerControl</string></arguments></invoke>");

   ShowMessage("The function returned: " + Response);
}
//---------------------------------------------------------------------------


void __fastcall TMainForm::ButtonCallActionScriptFunction2Click(
      TObject *Sender)
{
   WideString Response = TransparentFlashPlayerControl1->CallFunction("<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for TTransparentFlashPlayerControl</string></arguments></invoke>");

   ShowMessage("The function returned: " + Response);
}
//---------------------------------------------------------------------------

