在VB里有一结构体定义如下:
Type Struct_XfRec '消费记录结构
RecordID As Long '记录流水号
CardID As Long '卡流水号
CardValue As Long '卡余额
ConsumeMoney As Long '消费金额
ConsumeDate As String * 12 '消费时间
UseCount As Integer '卡使用次数
SaleOperatorID As Byte '营业员编号
DealFlag As Byte '餐类
Address As Integer '机器地址
End Type我转换成DELPHI的类型如下:
Type
Struct_XfRec=Record //消费记录结构
RecordID : Longint; //记录流水号
CardID : Longint; //卡流水号
CardValue : Longint; //卡余额
ConsumeMoney : Longint; //消费金额
ConsumeDate : string; //消费时间
UseCount : Longint; //卡使用次数
SaleOperatorID : String; //营业员编号
DealFlag : String; //餐类
Address : Integer; //机器地址
End;
上面的结构体作为一个函数的传入参数的类型,在VB下调用是没问题,但是在DELPHI下就报非法访问地址的英文错误!!
那个函数的声明如下:
function Get_Node_Curr_Rec_N(CommPortHandle:integer;var GudtConsumeData:struct_xfRec):longint;stdcall;far;external '...dll';我跟踪过,发现是 consumeData 类型的问题,也就是
VB的类型 string * 12
DELPHI的类型 string之间转换的问题,请大家帮忙分析一下要怎么转换二者???
Type Struct_XfRec '消费记录结构
RecordID As Long '记录流水号
CardID As Long '卡流水号
CardValue As Long '卡余额
ConsumeMoney As Long '消费金额
ConsumeDate As String * 12 '消费时间
UseCount As Integer '卡使用次数
SaleOperatorID As Byte '营业员编号
DealFlag As Byte '餐类
Address As Integer '机器地址
End Type我转换成DELPHI的类型如下:
Type
Struct_XfRec=Record //消费记录结构
RecordID : Longint; //记录流水号
CardID : Longint; //卡流水号
CardValue : Longint; //卡余额
ConsumeMoney : Longint; //消费金额
ConsumeDate : string; //消费时间
UseCount : Longint; //卡使用次数
SaleOperatorID : String; //营业员编号
DealFlag : String; //餐类
Address : Integer; //机器地址
End;
上面的结构体作为一个函数的传入参数的类型,在VB下调用是没问题,但是在DELPHI下就报非法访问地址的英文错误!!
那个函数的声明如下:
function Get_Node_Curr_Rec_N(CommPortHandle:integer;var GudtConsumeData:struct_xfRec):longint;stdcall;far;external '...dll';我跟踪过,发现是 consumeData 类型的问题,也就是
VB的类型 string * 12
DELPHI的类型 string之间转换的问题,请大家帮忙分析一下要怎么转换二者???
解决方案 »
- 安装delhpi的问题
- 怎么使用共用模块.
- fastreport放到dll的窗体中,同时这个dll作为子窗体出现错误。
- 在ISAPI中用CreateOleObject('Excel.Application')方式使用了Excel,如何确保在使用完毕或出现异常之后能正常释放Excel进程?
- 为什么我做的报表的所取的数据记录总是取的第一个记录
- 请问报表中的斜线如何打印啊!
- 在win2k/9x怎样获得Bios信息、Cpu、硬盘。
- 如何在程序中修改打印机设置?
- 怎样把delpi做的程序封装成一个类或做成一个模板可以被别人继承
- 请问各位,如何在主窗体显示出来后,前面再显示一个登陆窗体用于登陆????????????????
- 如何在listbox中显示数据表的行???
- 如何获取节点所在的层次?
DELPHI的类型 string[12]
array [1..12] of string;
VB不是很了解,转换后的语法,应该是这样的。ConsumeDate : array[0..11] of AnsiChar;
array [1..12] of AnsiChar;都不行,还是会报错.用 string[12] 没有报错,但是把结构体后面的值都弄错位了,应该
是 string[12]的长度和 string * 12 不一致吧?
而在Struct_XfRec=Record 中,由于不是packed,所以需要对齐,所以占用了16位。
如果VB中string *12 表示是12个字节的话,那么这里就应该是:
string[11],或array[0..11] of char
Struct_XfRec = packed record //消费记录结构
RecordID : LongInt; //记录流水号
CardID : LongInt; //卡流水号
CardValue : LongInt; //卡余额
ConsumeMoney : LongInt; //消费金额
ConsumeDate array [0..12-1] of AnsiChar; //消费时间
UseCount :SmallInt; //卡使用次数
SaleOperatorID : Byte; //营业员编号
DealFlag : Byte; //餐类
Address :SmallInt; //机器地址
End;
array[0..11] of ansiChar; //12个字节,为什么你要用11个字节呢
VB我没玩过,string *12到底是有几个字符?
按道理来说你定义Stirng[n],n等于多少都不会报错啊
当n小于你要字符的个数的时候,会自动截断