有如下的c++结构:
   typedef struct
   {
char sMsgID[10+1];
unsigned int nIsReply;
unsigned int nMsgFormat;
char sRecvTime[14+1];
char sSrcTermID[21+1];
char sDestTermID[21+1];
unsigned int nMsgLength;
char sMsgContent[252+1];
    }DeliverResp;    在delphi中如何定义和使用,最好是能提供了demo?

解决方案 »

  1.   

    C                  Delphi
    struct             record
    char               Char
    unsigned char      byte
    unsigned int       DWORD
    char c[10]         c: array [0..10-1] of Char
    LPCSTR             PChar
    LPVOID             Pointer
    void **data        var data(无类型,一个首地址)typedef int (*datatype) (int Param1, int* Param2);
    typedef void (*datatype);
    ==>
    type
      TDataType = function(Param1: Integer; Param2: PInteger): Integer;
      TDataType = procedure();其它类似,或在Windows都有提供
      

  2.   

    type
       TDeliverResp = Record
    sMsgID: string[10+1];//charsMsgID[10+1];
    nIsReply: DWord; //unsigned intnIsReply;
    nMsgFormat: Word; //unsigned intnMsgFormat;
    sRecvTime: string[14+1]; //charsRecvTime[14+1];
    sSrcTermID: string[21+1]; //charsSrcTermID[21+1];
    sDestTermID: string[21+1]; //charsDestTermID[21+1];
    nMsgLength: WORD; //unsigned intnMsgLength;
    sMsgContent: string[252+1]; //charsMsgContent[252+1];
        end; //}DeliverResp;var
      Form1: TForm1;
      DeliverResp: TDeliverResp;  //Delphi不允许C++那样定义类型的同时定义变量,还有变量只能在声明部分定义。
                                  //Delphi里没有union,想定义union的话用Delphi的变体记录(Variant parts in records)来代替。
    implementation{$R *.DFM}我爱Delphi!