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

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>

#ifndef ThreadQueDemoH
#define ThreadQueDemoH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <deque> // for queue
#include <SyncObjs.hpp> //for TCriticalSection
#include "WorkerThread.h"  // for friend declare and mWorker data member

// I prefer using struct for simple record, however, should change to class.
// The advantage using function pointer is that you could assigned many user-
// define function to excute for different item you push.
// Instead of using function pointer, you could create skillful function object
typedef
struct Item
{
  String mNameParam;
  int mNo;
  // could set more data member here
  void (*mpFunction)(const Item &);  //could assign user-define function 
}WORK_ITEM;


//---------------------------------------------------------------------------
class TMainForm : public TForm
{
// Using friend, cause i make some defined data members in protected block
friend void __fastcall Worker::Execute();


__published:	// IDE-managed Components
  TMemo *Memo1;
  TButton *PushWork;
  TButton *ThreadStart;
  TButton *StopThread;
  TMemo *Memo2;
  TLabel *Label1;
  TLabel *Label2;
  TButton *PauseThread;
  void __fastcall PushWorkClick(TObject *Sender);
  void __fastcall ThreadStartClick(TObject *Sender);
  void __fastcall StopThreadClick(TObject *Sender);
  void __fastcall PauseThreadClick(TObject *Sender);
  void __fastcall FormDestroy(TObject *Sender);
private:
  Worker *mWorker; // thread instance reference
protected:
  std::deque<WORK_ITEM> mQue; // our queue container
  HANDLE mDoWorkFlag;  // a flag to inform thread working or wait

public:		// User declarations
  __fastcall TMainForm(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
 