这两句C++的代码怎么翻译成 Delphi ( 积分: 100 )

I

idecl

Unregistered / Unconfirmed
GUEST, unregistred user!
-----------------
C++头文件中的声明
-----------------
typedef char TPTTCIVarChar16[17];
typedef char TPTTCIDate[9];

struct CPTTCISecInfoField
{
TPTTCIVarChar16 m_strSecID;
TPTTCIVarChar16 m_strSecType;
TPTTCIVarChar16 m_strExch;
};
struct CPTTCIPosInfoField : public CPTTCISecInfoField
{
TPTTCIVarChar16 m_strPlanID;
TPTTCIVarChar16 m_strFundID;
TPTTCIDate m_strBookDate;
TPTTCIVarChar16 m_strLSType;
TPTTCIVarChar16 m_strSAType;
TPTTCIVolumeType m_nInitHoldVol;
TPTTCIPriceType m_fInitCostPrc;
TPTTCIMoneyType m_fInitSumRlzPL;
TPTTCIMoneyType m_fInitSumFee

TPTTCIVolumeType m_nInitSumOpnVol;
TPTTCIVolumeType m_nHoldVol;
TPTTCIPriceType m_fCostPrc;
TPTTCIMoneyType m_fSumRlzPL;
TPTTCIMoneyType m_fSumFee;
TPTTCIMoneyType m_fFltPL;
......
};

CPTTCIRspInfoField * _stdcall TCI_ReqQryPlanInst(void *,const TPTTCIVarChar16 strInstID,const TPTTCIDate strBookDate,CPTTCIInstInfoField&amp
InstructData) ;

CPTTCIRspInfoField * _stdcall TCI_ReqDownPlanInst(void *,const TPTTCIVarChar16 strPlanID,const TPTTCIDate strBookDate, CPTTCIInstInfoField * &pInfoField,int &amp
RealSize);



请问这两句怎么翻译成Delphi?

我是这样翻的
TPTTCIVarChar16=array[0..16] of Char;
TPTTCIDate=array[0..8] of Char;

CPTTCISecInfoField = record
m_strSecID : TPTTCIVarChar16

m_strSecType : TPTTCIVarChar16;
m_strExch : TPTTCIVarChar16

end;
TCPTTCIPosInfoField = record
m_secifo : CPTTCISecInfoField;
m_strPlanID : TPTTCIVarChar16 ;
m_strFundID : TPTTCIVarChar16

m_strBookDate : TPTTCIDate

m_strLSType : TPTTCIVarChar16

m_strSAType : TPTTCIVarChar16

m_nInitHoldVol : TPTTCIVolumeType

m_fInitCostPrc : TPTTCIPriceType ;
......
end;
CPTTCIPosInfoField = array of TCPTTCIPosInfoField;
PTCPTTCIPosInfoField = ^TCPTTCIPosInfoField;

function TCI_ReqQryPlanInst(ptr:pointer;var strInstID:TPTTCIVarChar16;var strBookDate:TPTTCIDate;var InstructData:CPTTCIInstInfoField):CPTTCIRspInfoField;

function TCI_ReqDownPlanInst(ptr:pointer;var strPlanID:TPTTCIVarChar16;var strBookDate:TPTTCIDate;var pInfoField:CPTTCIInstInfoField
var RealSize:integer):CPTTCIRspInfoField;

但是不正确,我在同一个窗体类(TFrmChild)创建的两个Frmchild1,Frmchild2实例的同一位置调用这个函数,第一个窗体调用时正常,但第二个再调用的时候,报地址错误(000000),地址不存在,我跟踪后发现两次声明的(CPTTCIInstInfoField)变量的地址一样。请高手指点,谢谢
 
L

lovezyp

Unregistered / Unconfirmed
GUEST, unregistred user!
一般牵扯到指针的都不好翻译!语句虽然可以翻译,但是可能不起任何作用
 
I

idecl

Unregistered / Unconfirmed
GUEST, unregistred user!
TO : LOVEZYP
应该总有办法吧,Delphi不是说完全与C++兼容吗?
 
F

fanybul

Unregistered / Unconfirmed
GUEST, unregistred user!
你粘贴出来的代码太多了,我没看。
但是我的做法就是,先理解了C++的代码是实现什么功能的,那些个函数有哪些参数是重要的,然后你通过DELPHI语言来实现就行了,至于怎么样实现,不是一定要按照C++里那几句代码来吧,只要你把要实现的功能给它做出来就行了,这样的方法应该很多吧。
 
C

cpj7406

Unregistered / Unconfirmed
GUEST, unregistred user!
帮你顶一下!
实在没有时间,否则我倒真是愿意试试,顺便复习一下 C++。

发贴的这位朋友,这种问题你不要说是“翻译”,实际上我估计是有一个 C++ 开发的 dll 标准动态链接库,你希望在 Delphi 开发中加载并调用之功能。

如果真是翻译,那在难以对应语言特性的情况下就按照 fanybul 朋友所说的做好了。
 
I

idecl

Unregistered / Unconfirmed
GUEST, unregistred user!
cpj7406,对,其实应该说怎么翻译头文件和Dll函数
 
I

idecl

Unregistered / Unconfirmed
GUEST, unregistred user!
CPTTCIInstInfoField&amp
InstructData
CPTTCIInstInfoField * &pInfoField

或者说这两个应该怎么传参数进去?

CPTTCIInstInfoField是一个struct,第一个应该是传一个指向CPTTCIInstInfoField的指针或引用,那么第二个呢?我只知道第二个返回的是一个CPTTCIInstInfoField的数组,但不知道C++是怎么实现的,Delphi又应该怎么传参数进行?

-----------------------
下面是C++的两个函数声明
------------------------
CPTTCIRspInfoField * _stdcall TCI_ReqQryPlanInst(void *,const TPTTCIVarChar16 strInstID,const TPTTCIDate strBookDate,CPTTCIInstInfoField&amp
InstructData) ;

CPTTCIRspInfoField * _stdcall TCI_ReqDownPlanInst(void *,const TPTTCIVarChar16 strPlanID,const TPTTCIDate strBookDate, CPTTCIInstInfoField * &pInfoField,int &amp
RealSize);
 
顶部