VB代码转为DELPHI,在线急等 ( 积分: 300 )

  • 主题发起人 主题发起人 monkeyboys
  • 开始时间 开始时间
M

monkeyboys

Unregistered / Unconfirmed
GUEST, unregistred user!
Attribute VB_Name = &quot;comsubs&quot;<br>Option Explicit<br><br>Type CardStruct<br> &nbsp; &nbsp;cardtype &nbsp; &nbsp; As Byte &nbsp;<br> &nbsp; &nbsp;HotelID(2) &nbsp; As Byte <br> &nbsp; &nbsp;AreaID &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;FloorID &nbsp; &nbsp; &nbsp;As Byte <br> &nbsp; &nbsp;roomid &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;CardID &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;OffOn &nbsp; &nbsp; &nbsp; &nbsp;As Byte <br> &nbsp; &nbsp;SDate(4) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;EDate(4) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;STiem(1) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;ETime(1) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;FloorCot &nbsp; &nbsp; As Byte <br>End Type<br><br><br>Public Const INVALID_HANDLE_VALUE = -1<br>Public commhandle As Long<br>Public FKQstatus &nbsp;As Boolean<br><br><br>Public Const CardOk &nbsp; As Integer = 0<br>Public Const CardErr &nbsp;As Integer = 1<br><br>Public RdCard &nbsp; &nbsp; &nbsp;As CardStruct<br>Public icdev As Long &nbsp; &nbsp;<br>Dim st As Integer &nbsp; <br><br>Public Declare Function auto_init Lib &quot;comdll.dll&quot; (ByVal CommPort As Long, ByVal Baud As Long) As Long &nbsp; <br>Public Declare Function ic_exit Lib &quot;comdll.dll&quot; (ByRef commhandle As Long) As Long &nbsp; &nbsp; &nbsp; &nbsp; <br>Public Declare Function csc4150hex Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keystr As Byte) As Long<br><br>Public Declare Function RDKEYRF Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keyinfo As Byte) As Long<br>Public Declare Function WRKEYRF Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keyinfo As Byte) As Long<br><br><br>Function OpenIcDev(port As Integer) As Integer<br>Dim temp As Integer<br> &nbsp; &nbsp;icdev = auto_init(port, 9600)<br><br>End Function<br><br><br>Function CloseIcDev()<br> &nbsp; &nbsp;st = ic_exit(icdev)<br>End Function<br><br><br>Function PassIcDev() As Integer<br>Dim keystr(3) As Byte<br>keystr(0) = &amp;H1<br>keystr(1) = &amp;H2<br>keystr(2) = &amp;H2<br>keystr(3) = &amp;H24<br>st = csc4150hex(icdev, keystr(0))<br>Exit Function<br>End Function<br><br><br>Function WtCardICdev(CardIn As CardStruct) As Integer<br>Dim offset &nbsp; &nbsp;As Integer<br>Dim length &nbsp; &nbsp;As Integer<br>Dim i &nbsp; &nbsp;As Integer<br>st = WRKEYRF(icdev, CardIn.cardtype)<br>If st &lt;&gt; 0 Then<br> &nbsp; WtCardICdev = CardErr<br>Else<br> &nbsp; WtCardICdev = CardOk<br>End If<br><br>End Function<br><br><br><br>Function RdCardICdev() As Integer<br>Dim offset &nbsp; &nbsp;As Integer<br>Dim length &nbsp; &nbsp;As Integer<br>st = RDKEYRF(icdev, RdCard.cardtype)<br>If st &lt;&gt; 0 Then<br> &nbsp; RdCardICdev = CardErr<br> &nbsp; Exit Function<br>Else<br> &nbsp; RdCardICdev = CardOk<br>End If<br><br>End Function<br><br>本人对VB确实不懂,有劳各位高手将以上代码转译为DELPHI<br>测试通过,立即给分.
 
Attribute VB_Name = &quot;comsubs&quot;<br>Option Explicit<br><br>Type CardStruct<br> &nbsp; &nbsp;cardtype &nbsp; &nbsp; As Byte &nbsp;<br> &nbsp; &nbsp;HotelID(2) &nbsp; As Byte <br> &nbsp; &nbsp;AreaID &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;FloorID &nbsp; &nbsp; &nbsp;As Byte <br> &nbsp; &nbsp;roomid &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;CardID &nbsp; &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;OffOn &nbsp; &nbsp; &nbsp; &nbsp;As Byte <br> &nbsp; &nbsp;SDate(4) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;EDate(4) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;STiem(1) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;ETime(1) &nbsp; &nbsp; As Byte <br> &nbsp; &nbsp;FloorCot &nbsp; &nbsp; As Byte <br>End Type<br><br><br>Public Const INVALID_HANDLE_VALUE = -1<br>Public commhandle As Long<br>Public FKQstatus &nbsp;As Boolean<br><br><br>Public Const CardOk &nbsp; As Integer = 0<br>Public Const CardErr &nbsp;As Integer = 1<br><br>Public RdCard &nbsp; &nbsp; &nbsp;As CardStruct<br>Public icdev As Long &nbsp; &nbsp;<br>Dim st As Integer &nbsp; <br><br>Public Declare Function auto_init Lib &quot;comdll.dll&quot; (ByVal CommPort As Long, ByVal Baud As Long) As Long &nbsp; <br>Public Declare Function ic_exit Lib &quot;comdll.dll&quot; (ByRef commhandle As Long) As Long &nbsp; &nbsp; &nbsp; &nbsp; <br>Public Declare Function csc4150hex Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keystr As Byte) As Long<br><br>Public Declare Function RDKEYRF Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keyinfo As Byte) As Long<br>Public Declare Function WRKEYRF Lib &quot;comdll.dll&quot; (ByVal commhandle As Long, ByRef keyinfo As Byte) As Long<br><br><br>Function OpenIcDev(port As Integer) As Integer<br>Dim temp As Integer<br> &nbsp; &nbsp;icdev = auto_init(port, 9600)<br><br>End Function<br><br><br>Function CloseIcDev()<br> &nbsp; &nbsp;st = ic_exit(icdev)<br>End Function<br><br><br>Function PassIcDev() As Integer<br>Dim keystr(3) As Byte<br>keystr(0) = &amp;H1<br>keystr(1) = &amp;H2<br>keystr(2) = &amp;H2<br>keystr(3) = &amp;H24<br>st = csc4150hex(icdev, keystr(0))<br>Exit Function<br>End Function<br><br><br>Function WtCardICdev(CardIn As CardStruct) As Integer<br>Dim offset &nbsp; &nbsp;As Integer<br>Dim length &nbsp; &nbsp;As Integer<br>Dim i &nbsp; &nbsp;As Integer<br>st = WRKEYRF(icdev, CardIn.cardtype)<br>If st &lt;&gt; 0 Then<br> &nbsp; WtCardICdev = CardErr<br>Else<br> &nbsp; WtCardICdev = CardOk<br>End If<br><br>End Function<br><br><br><br>Function RdCardICdev() As Integer<br>Dim offset &nbsp; &nbsp;As Integer<br>Dim length &nbsp; &nbsp;As Integer<br>st = RDKEYRF(icdev, RdCard.cardtype)<br>If st &lt;&gt; 0 Then<br> &nbsp; RdCardICdev = CardErr<br> &nbsp; Exit Function<br>Else<br> &nbsp; RdCardICdev = CardOk<br>End If<br><br>End Function<br><br>本人对VB确实不懂,有劳各位高手将以上代码转译为DELPHI<br>测试通过,立即给分.
 
自己顶一下
 
再顶一下
 
想帮你,但代码太长了.其它代码很简单
 
unit comsubs;<br><br>interface<br><br>type<br> &nbsp;CardStruct = record<br> &nbsp; &nbsp;cardtype: Byte;<br> &nbsp; &nbsp;HotelID: array[0..2] of Byte;<br> &nbsp; &nbsp;AreaID: Byte;<br> &nbsp; &nbsp;FloorID: Byte;<br> &nbsp; &nbsp;roomid: Byte;<br> &nbsp; &nbsp;CardID: Byte;<br> &nbsp; &nbsp;OffOn: Byte;<br> &nbsp; &nbsp;SDate: array[0..4] of Byte;<br> &nbsp; &nbsp;EDate: array[0..4] of Byte;<br> &nbsp; &nbsp;STiem: array[0..1] of Byte;<br> &nbsp; &nbsp;ETime: array[0..1] of Byte;<br> &nbsp; &nbsp;FloorCot: Byte;<br> &nbsp;end;<br><br>Const<br> &nbsp;INVALID_HANDLE_VALUE = -1;<br> &nbsp;CardOk = 0;<br> &nbsp;CardErr = 1;<br><br>var<br> &nbsp;commhandle: LongInt;<br> &nbsp;FKQstatus: Boolean;<br> &nbsp;RdCard: CardStruct;<br> &nbsp;icdev: LongInt;<br> &nbsp;st: Integer;<br> &nbsp;function auto_init(const CommPort: LongInt; const Baud: LongInt):LongInt; stdcall; external 'comdll.dll';<br> &nbsp;function ic_exit(var commhandle: LongInt): LongInt; stdcall; &nbsp;external 'comdll.dll';<br> &nbsp;function csc4150hex(const commhandle: LongInt; var keystr: Byte): LongInt; stdcall; external 'comdll.dll';<br> &nbsp;function RDKEYRF(const commhandle: LongInt; var keyinfo: Byte): LongInt; stdcall; &nbsp;external 'comdll.dll';<br> &nbsp;function WRKEYRF(const commhandle: LongInt; var keyinfo: Byte): LongInt; stdcall; &nbsp;external 'comdll.dll';<br><br>implementation<br><br>function OpenIcDev(port: Integer): Integer;<br>var<br> &nbsp;temp: Integer;<br>begin<br> &nbsp;icdev := auto_init(port, 9600);<br>end;<br><br>procedure CloseIcDev;<br>begin<br> &nbsp;st := ic_exit(icdev);<br>end;<br><br>function PassIcDev: Integer;<br>var<br> &nbsp;keystr: array[0..3] of Byte;<br>begin<br> &nbsp;keystr[0] := $1;<br> &nbsp;keystr[1] := $2;<br> &nbsp;keystr[2] := $2;<br> &nbsp;keystr[3] := $24;<br> &nbsp;st := csc4150hex(icdev, keystr[0]);<br>end;<br><br>function WtCardICdev(CardIn: CardStruct): Integer;<br>var<br> &nbsp;offset: Integer;<br> &nbsp;length: Integer;<br> &nbsp;i: Integer;<br>begin<br> &nbsp;st := WRKEYRF(icdev, CardIn.cardtype);<br> &nbsp;if st &lt;&gt; 0 Then<br> &nbsp; &nbsp;Result := CardErr<br> &nbsp;else<br> &nbsp; &nbsp;Result := CardOk;<br>end;<br><br>function RdCardICdev: Integer;<br>var<br> &nbsp;offset: Integer;<br> &nbsp;length: Integer;<br>begin<br> &nbsp;st := RDKEYRF(icdev, RdCard.cardtype);<br> &nbsp;If st &lt;&gt; 0 Then<br> &nbsp;begin<br> &nbsp; Result := CardErr;<br> &nbsp; Exit;<br> &nbsp;end<br> &nbsp;else<br> &nbsp; Result := CardOk;<br>end;<br><br>end.
 
谢谢czcn, 待我测试一下,通过后立即发分
 
to czcn:<br>st := csc4150hex(icdev, keystr[0]);<br>当程序执行到这一句的时候报错
 
这里是一个把VB代码转成Delphi代码的工具,你下看看吧:<br>http://www.lbbsoftware.com/free/vb2delphiv1.3.zip
 
to wzwcn :<br>有病毒,无法打开
 
仔细看看这句。。<br>function csc4150hex(const commhandle: LongInt; const keystr: Byte): LongInt; stdcall; stdcall; &nbsp;external 'comdll.dll';<br>你说的错误可能是类型不匹配。。<br>st := csc4150hex(icdev, keystr[0]);
 
&gt;&gt; st := csc4150hex(icdev, keystr[0]);<br>&gt;&gt; 当程序执行到这一句的时候报错<br>把错误贴出来看一看.不过上面确实多打了一个stdcall;,删掉试试
 
我把function csc4150hex(const commhandle: LongInt; const keystr: Byte): LongInt; stdcall; stdcall; &nbsp;external 'comdll.dll'定义改为:<br><br>function csc4150hex(const commhandle: LongInt; var keystr: Byte): LongInt; stdcall; stdcall; &nbsp;external 'comdll.dll';<br>就不报错了.但是现在我用DELPHI调用后,得不到正确结果.
 
function csc4150hex<br>得不到正确的结果吗??<br><br>vb 调用的结果你知道吗??
 
这句多了一个stdcall你删了吗?<br><br>ByVal和ByRef是不一样.不过我也记不清了.<br>不过我看上面的函数都没更改参数的值,所以我都加了const;
 
多出的 stdcall 开始我就删掉了.<br>现在就是搞不明白我应该传什么样的参数进去才是正确的.<br>是传地址还是传值进去<br>VB的东西我实在搞不清楚
 
应该ByVal是值,ByRef是地址<br>如果结果不正确.会不会是<br>st是integer;<br>csc4150hex返回的是LongInt;<br>的关系?
 
多人接受答案了。
 
后退
顶部