C++代码转化! ( 积分: 100 )

  • 主题发起人 主题发起人 boycxd
  • 开始时间 开始时间
B

boycxd

Unregistered / Unconfirmed
GUEST, unregistred user!
麻烦各位下面这段代码如何转化为DELPHI代码!我C++不行,谢谢了!
SC_PankouAsk *pp = (SC_PankouAsk *)tmpbuf;
pp->m_Head.m_nType = SC_PANKOU;
pp->m_Head.m_cStatus = 1;
pp->m_Head.m_lIndex = m_lAskIndex;
pp->m_sID.m_nIndex = nIndex;
pp->m_sID.m_wMarket = wMarket;
pp->m_lDate = pm->m_lDate;
nAskLen = sizeof(SC_PankouAsk);
///////////////////////////////////////////////////////
不好意思,刚才代码没发全。
void CSCDemoDlg::_SCAskData()
{
......
char tmpbuf[1024];
long lStartDate, lEndDate;
......
sprintf(tmpbuf, "%d%02d%02d", m_dateStart.GetYear(), m_dateStart.GetMonth(), m_dateStart.GetDay());
lStartDate = atol(tmpbuf);
sprintf(tmpbuf, "%d%02d%02d", m_dateend.
GetYear(), m_dateend.
GetMonth(), m_dateend.
GetDay());
lEndDate = atol(tmpbuf);
memset(tmpbuf, 0, 1024);
......
SC_PankouAsk *pp = (SC_PankouAsk *)tmpbuf;
pp->m_Head.m_nType = SC_PANKOU;
pp->m_Head.m_cStatus = 1;
pp->m_Head.m_lIndex = m_lAskIndex;
pp->m_sID.m_nIndex = nIndex;
pp->m_sID.m_wMarket = wMarket;
pp->m_lDate = pm->m_lDate;
nAskLen = sizeof(SC_PankouAsk);
......
m_Dll.SCAskData(tmpbuf, nAskLen);
}
 
var
pp ,
tmpbuf : ^SC_PankouAsk
begin
pp:=tmpbuf;
pp^.m_Head.m_nType:= SC_PANKOU;
pp^.m_Head.m_cStatus := 1;
pp^.m_Head.m_lIndex := m_lAskIndex;
pp^.m_sID.m_nIndex := nIndex;
pp^.m_sID.m_wMarket := wMarket;
pp^.m_lDate := pm^.m_lDate;
nAskLen: = sizeof(SC_PankouAsk);

只能根据你现在列出的语句翻与了!呵呵!
 
呵呵,(谢谢你) and (非常感谢) 试验成功后吗上加分!
 
不好意思,刚才代码没发全。
void CSCDemoDlg::_SCAskData()
{
......
char tmpbuf[1024];
long lStartDate, lEndDate;
......
sprintf(tmpbuf, "%d%02d%02d", m_dateStart.GetYear(), m_dateStart.GetMonth(), m_dateStart.GetDay());
lStartDate = atol(tmpbuf);
sprintf(tmpbuf, "%d%02d%02d", m_dateend.
GetYear(), m_dateend.
GetMonth(), m_dateend.
GetDay());
lEndDate = atol(tmpbuf);
memset(tmpbuf, 0, 1024);
......
SC_PankouAsk *pp = (SC_PankouAsk *)tmpbuf;
pp->m_Head.m_nType = SC_PANKOU;
pp->m_Head.m_cStatus = 1;
pp->m_Head.m_lIndex = m_lAskIndex;
pp->m_sID.m_nIndex = nIndex;
pp->m_sID.m_wMarket = wMarket;
pp->m_lDate = pm->m_lDate;
nAskLen = sizeof(SC_PankouAsk);
......
m_Dll.SCAskData(tmpbuf, nAskLen);
}
 
理解几个关键点就行了
tmpbuf声明成 array[0..1024] of char;
sprintf 这个地方是将m_datestart的结构中的变量凑成一个'YYYYMMDD'的日期字符串
attl就是将日期字符串转换成一个长整形
delphi里不需要用tmpbuf过渡,不见得跟他写得一样,直接用formatdatetime转就可以了
memset 这儿用 fillchar(tmpbuf, sizeof(tmpbuf), 0) //初始化
pp->m_Head.m_nType = SC_PANKOU;
pp->m_Head.m_cStatus = 1;
pp->m_Head.m_lIndex = m_lAskIndex;
pp->m_sID.m_nIndex = nIndex;
pp->m_sID.m_wMarket = wMarket;
pp->m_lDate = pm->m_lDate;
上面这些没什么好说的,指什的取变量操作 pp^.m_head.m_cstatus := 1;类似于这样
SC_PankouAsk *pp = (SC_PankouAsk *)tmpbuf;
这个实际上是把一个指针的值转换成一个字符数组,然后到用的时候再转换回来,常见于
dll和socket中
move(pp^, tmpbuf, sizeof(pp));
在delphi里这个move操作放在那些赋值的后面
 
多人接受答案了。
 
后退
顶部