//****************************************************************
//****************************************************************
//---------------------------------------------------------------------------
int DMY(TDateTime, char); //prototype
int DMY(TDateTime DDate, char dmy)
{// returns day, month or year number from TDateTime date
//Example usage: DMY(Now(), 'Y'); returns current year as integer
Word Year, Month, Day, Hour, Min, Sec, MSec;
DecodeDate(DDate, Year, Month, Day);
switch (dmy)
{
case 'd': case 'D': return Day;
case 'm': case 'M': return Month;
case 'y': case 'Y': return Year;
}
return 0;
}
//---------------------------------------------------------------------------
int DMY(AnsiString, char); //overload prototype
int DMY(AnsiString SDate, char dmy)
{//Returns day, time, year integer from string date
//Example usage: DMY("12/30/1998", 'M'); returns 30
return DMY(StrToDate(SDate), dmy);
}

//****************************************************************
//****************************************************************
//----- The HandyDandy dBase IIF() function ---------
Variant IIF(bool, Variant, Variant); //prototype
Variant IIF(bool Cond, Variant Res1, Variant Res2)
{if (Cond) return Res1; else return Res2;}


//****************************************************************
//****************************************************************
//----- Handy FirstInstance function-------
// returns false if this is not the first instance of your .exe
bool FirstInstance(const char *MutexName)
{// MutexName must be a very unique application name string - eg. "OurSuperAccountingProgram"
// try to create unique mutex HANDLE (discarded on exit of program)
CreateMutex(NULL, true, MutexName); //HANDLE
return !GetLastError();} // if no errors, this is the first instance 

//***************FirstInstance() Example***************************
/*
You can just use the function into your main project file
(Project1.cpp or whatever) like this:

...
...
bool FirstInstance(const char *MutexName)
{// MutexName must be a very unique application name string - eg. "OurSuperAccountingProgram"
//try to create unique mutex HANDLE (discarded on exit of program)
CreateMutex(NULL, true, MutexName); //HANDLE
return !GetLastError();} // This is the first instance if no errors

//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
if (!FirstInstance("OurSuperAccountingProgram")){
  MessageBox (NULL, "Accounting program is already running",
    "Notice", MB_OK | MB_ICONEXCLAMATION);
  return 1;}

try{
  Application->Initialize();
  ... etc ...

*/
//****************************************************************
//****************************************************************

//--------- the missing math Round function -------------
#include <math.h>
double Round(double dNumber, int dec)
{//rounds dNumber to dec decimal places
return double(int(dNumber*pow(10, dec)+ 0.501)/pow(10, dec));}
//****************************************************************
//****************************************************************
