help me VC++ code convert to Delphi code

huayan889

Турист
Регистрация
6 Июл 2007
Сообщения
3
Реакции
0
Credits
4
/-----------------------------------------------------------
#define MAX_M_NUM 256

#define MAX_P_NUM 64
#define MAX_T_NUM (32*MAX_P_NUM)


enum REMOVE_STATE
{
REMOVE_STATE_NONE = 0,
REMOVE_STATE_START = 1,
REMOVE_STATE_READY = 2,
};

enum M_STATE {
M_Free,
M_CC_INPUT,

M_CC_OK,
M_M_INPUT,
};

typedef struct
{
char m_s32FType;
short m_s32FCnl;
}CallID_t;

typedef struct
{
long m_s32DevMain;
logn m_s32ID;
long m_s32DevNum;
}Dev_List_Head_t

typedef struct
{
short m_s16Main;
short m_s16Sub;
Char m_s8ID;
Char m_Ru1[1];
short m_s16ID;
short m_s16Group;
char m_Ru2[2];
CallID_t m_CallID;
}DeviceID_t;


typedef struct
{
Char m_s8ID;
short m_s16ID;
}CNL_MAP_TABLE;


typedef struct
{
DeviceID_t deviceID;
int iSeqID;
.....
M_STATE ModuleState;

} T_STRUCT;

typedef struct
{
unsigned long m_s32Handle;
DeviceID_t m_DeviceID;
long m_s32ESize;
long m_s32EType;
}Evt_t;

enum V_STATE {
V_WAITOPEN,
V_FREE,
V_USED,
V_WAIT_REMOVE
} ;

typedef struct
{
DeviceID_t deviceID;
int iSeqID;
DeviceID_t UsedDevID;
V_STATE State
} V_STRUCT;

typedef struct
{
// ----------------
DeviceID_t deviceID;
int iSeqID;
....
Byte u8E1Type;
} P_STRUCT;


// -------------------------------------------------------------------------------------
DEVICE_RES AllDeviceRes[MAX_M_NUM];

int iTotalM = 0;
char MapT_M[MAX_M_NUM];

int iTotalP = 0;
int iTotalPOpened = 0;
CNL_MAP_TABLE MapT_P[MAX_P_NUM];

int iTotalT = 0;
int iTotalTOpened = 0;
CNL_MAP_TABLE MapT_T[MAX_T_NUM];

int iTotalV = 0;
int iTotalVOpened = 0;
int iTotalVFree = 0;
CNL_MAP_TABLE MapT_V[MAX_T_NUM];

//the above define and struct is description for the follow statements, not necessary for convert -------

typedef struct
{
long lFlag;
DeviceID_t deviceID;
int iSeqID;
bool OpenFlag;
bool ErrFlag;
REMOVE_STATE RemoveState;

long lVNum;
long lVOpened;
long lVFreeNum;
V_STRUCT *pV;

long lPNum;
long lPOpened;
P_STRUCT *pP;

long lTNum;
long lTOpened;
T_STRUCT *pT;

}DEVICE_RES;




#define M_OneV(DevID) AllDeviceRes[(DevID).m_s8ID].pV[(DevID).m_s16ID]
#define M_OneP(DevID) AllDeviceRes[(DevID).m_s8ID].pP[(DevID).m_s16ID]
#define M_OneT(DevID) AllDeviceRes[(DevID).m_s8ID].pT[(DevID).m_s16ID]

DJ_S32 PlayFile ( DeviceID_t *pVDevID, char *s8FileName, byte u8PTag, bool bIsQueue = false );

void TWork ( T_STRUCT *pOneT, Evt_t *pEvt );


//=======================================================================================
extern int iPWork;


// -------------------------------------------------------------------------------------
void DispEvtInfo ( Evt_t *pEvt )
{
char TmpStr[256];
char TmpS[128];

Dev_List_Head_t * pDevList = NULL;

sprintf ( TmpStr, "EVT(%4d) : ", pEvt->m_s32ESize );

switch ( pEvt->m_s32EType )
{
.....................

case E_QUERY_DEV:
pDevList = (Dev_List_Head_t *) FetchEventData(pEvt);
........

default:
break;

}

}

// --------------------------------------------------------------------------
void CloseDeviceOK ( DeviceID_t *pDevice )
{
T_STRUCT *pOneT;

.......

if ( pDevice->m_s16Main == DEVMAIN_PORT )
{
M_OneP(*pDevice).bOpenFlag = false;

.......
}
}

void OpenAllDevice_D ( char s8ModID )
{
int i;

......

for ( i = 0; i < AllDeviceRes[s8ModID].lVocNum; i++ )
{
OpenVocDevice ( &AllDeviceRes[s8ModID].pV );
}
.......
}

void HandleState ( Evt_t *pEvt )
{
T_STRUCT *pOneT;
P_STRUCT *pOneP;
......

if ( pEvt->m_DeviceID.m_s16Main == DEVMAIN_PORT )
{
pOneP = &M_OneP(pEvt->m_DeviceID);

pOneP->u8E1Type = (pGenData->m_s32DevState >> 16) & 0xFF;
}
............
}

void FreeOneDevRes ( int ID )
{
if ( AllDeviceRes[ID].p != NULL )
delete [] AllDeviceRes[ID].pV;
.......

memset ( &AllDeviceRes[ID], 0, sizeof (DEVICE_RES) );
}


// --------------------------------------------------------------------------
void RefreshMapTable ( void )
{
int i, j;
int TCount, VCount, PCount, MCount;
int iModSeqID;

MCount = TCount = VCount = PCount = 0;
for ( i = 0; i < MAX_M_NUM; i ++ )
{
if ( AllDeviceRes.lFlag == 1 )
{
AllDeviceRes.iSeqID = MCount;
MapT_M[MCount] = i;
..........

iModSeqID = 0;
for ( j = 0; j < AllDeviceRes.lTNum; j ++ )
{
AllDeviceRes.pT[j].iSeqID = TCount;
MapT_T[TCount].m_s8ID = AllDeviceRes.pT[j].deviceID.m_s8ID;
......
if ( AllDeviceRes.pT[j].deviceID.m_s16Sub != DEVSUB_UNUSABLE )
{
AllDeviceRes.pT[j].iModSeqID = iModSeqID;
....
}
}
}
}
.....

}

void AddDevRes_T ( char s8ModID, Dev_List_Head_t *pDevList )
{
DJ_S32 s32Num;
int i;
char TmpStr[256];

s32Num = pDevList->m_s32DevNum;

if ( (AllDeviceRes[s8ModID].lTNum == 0) && (s32Num > 0) )
{
AllDeviceRes[s8ModID].pT = new T_STRUCT[s32Num];
if( !AllDeviceRes[s8ModID].pT )
{
AllDeviceRes[s8ModID].lTNum = 0;

sprintf ( TmpStr, "new T_STRUCT[%d] fail in AddDevRes_T()" );
}
else
{

memset ( AllDeviceRes[s8ModID].pT, 0, sizeof(T_STRUCT)*s32Num );

DeviceID_t *pDev;

pDev = (DeviceID_t *)((BYTE *)pDevList + sizeof(Dev_List_Head_t));

for ( i = 0; i < s32Num; i ++ )
{
AllDeviceRes[s8ModID].pT.deviceID = pDev;
AllDeviceRes[s8ModID].pT.State = T_WAITOPEN;
}
}
}
else if ( (AllDeviceRes[s8ModID].lTkNum > 0) && (s32Num == 0) )
{
for ( i = 0; i < AllDeviceRes[s8ModID].lTNum; i ++ )
{
if ( AllDeviceRes[s8ModID].pT.State != T_WAITOPEN )
CloseDeviceOK ( &AllDeviceRes[s8ModID].pT.deviceID );
}

delete [] AllDeviceRes[s8ModID].pT;
AllDeviceRes[s8ModID].pT = NULL;
}

}



Void E_Handler( unsigned long ePrm)
{
Evt_t * pEvt = NULL;
Dev_List_Head_t * pDevList = NULL;


pEvt = (Evt_t *) ePrm;
DispEvtInfo ( pEvt );

switch ( pEvt->m_s32EType )
{
case EVT_QUERY_DEVICE:
if ( ( iPWork == 0 ) || (pEvt->m_DeviceID.m_s8ID == iPWorkID) )
{
pDevList = ( Dev_List_Head_t *) FetchEventData(pEvt);
AddDeviceRes ( pDevList );
}
break;

case EVT_OPEN_DEVICE:
OpenDeviceOK ( &pEvt->m_DeviceID );
break;
........
default:
if ( pEvt->m_DeviceID.m_s16Main == DEVMAIN_CH )
{
TWork ( &M_OneT(Evt->m_DeviceID), pEvt );
}
else if ( pEvt->m_DeviceID.m_s16Main == DEVMAIN_V )
{
DeviceID_t *pDevID;

pDevID = &M_OneV(pEvt->m_DeviceID).UsedDevID;

if ( pDevID->m_s16Main == DEVMAIN_CH )
{
TWork ( &M_OneT(*pDevID), pEvt );
}
}
break;
}

}

memcpy( pParam->m_CT.m_u8NumH, TmpStr, pParam->m_CT.m_u8NumHLen );
//----------------------------------------------------------------------------------









//:confused::confused::D:D
//Everybody Merry Christmas Спасибо
 

jcooper66

Местный
Регистрация
6 Сен 2007
Сообщения
24
Реакции
6
Credits
46
Actually the above appears quite easy., but there is little incentive to assist you with this.

To convert constants
Для просмотра ссылки Войди или Зарегистрируйся

for other ideas
Для просмотра ссылки Войди или Зарегистрируйся

like I said there is too little incentive to convert this.
You can probably get a component that solves your problem at
torry.ru or JEDI / JVCL project that already does what your doing
in a much smoother fashion

Good luck