100 分请各位老大把下面的VB代码翻译成Delphi

qinget 2007-10-26 10:24:00
Public Function LRC(str As String) As String
c = 0
l = Len(str)
For c = c + 1 To l
c_data = Mid$(str, c, 2)
d_lrc = d_lrc + Val("&H" + c_data)
c = c + 1
Next c
If d_lrc > &HFF Then
d_lrc = d_lrc Mod &H100
End If
h_lrc = Hex(&HFF - d_lrc + 1)
If Len(h_lrc) > 2 Then
h_lrc = Mid(h_lrc, Len(h_lrc) - 1, 2)
End If
LRC = h_lrc
End Function
...全文
54 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinget 2007-10-27
  • 打赏
  • 举报
回复
谢谢了edongxu!!
edongxu 2007-10-26
  • 打赏
  • 举报
回复
不过不像VB,变量事先要声明的!!!!!
还有,delphi的FOR语句步长只能为一,我改成while语句了,其他也改了些,已达到预定目标;
Function LRC(const str : String): String ;
var
c,L,d_lrc:integer;
c_data,h_lrc:string;

begin
c := 1;
L := Length(str);
d_lrc:=0;

while c < L do
begin
c_data := copy(str, c, 2);
d_lrc := d_lrc + strtoint('$' + c_data);
c:=c+2;
end;

If d_lrc > $FF Then
begin
d_lrc := d_lrc Mod $100;
End;

h_lrc := inttoHex(($FF - d_lrc + 1),8);

while pos('0',h_lrc) = 1 do delete(h_lrc,1,1);

If Length(h_lrc) > 2 Then h_lrc := copy(h_lrc, Length(h_lrc) - 1, 2);

result := h_lrc;

End;
edongxu 2007-10-26
  • 打赏
  • 举报
回复


Function LRC(str : String): String ;
begin
c := 0;
l := Length(str);

For c := c + 1 To l do
begin
c_data: = copy(str, c, 2);
d_lrc := d_lrc + strtoint('$' + c_data);
end;

If d_lrc > $FF Then
begin
d_lrc := d_lrc Mod $100;
End;

h_lrc = inttoHex(($FF - d_lrc + 1),8);

If Length(h_lrc) > 2 Then
h_lrc := copy(h_lrc, Len(h_lrc) - 1, 2);


LRC := h_lrc;

End;
edongxu 2007-10-26
  • 打赏
  • 举报
回复


Function LRC(str : String): String ;
begin
c := 0;
l := Length(str);

For c := c + 1 To l do
begin
c_data: = copy(str, c, 2);
d_lrc := d_lrc + strtoint('$' + c_data);
end;

If d_lrc > $FF Then
begin
d_lrc := d_lrc Mod $100;
End;

h_lrc = inttoHex(($FF - d_lrc + 1),8);

If Length(h_lrc) > 2 Then
h_lrc = copy(h_lrc, Len(h_lrc) - 1, 2);


LRC = h_lrc;

End;
qinget 2007-10-26
  • 打赏
  • 举报
回复
不够可以加分

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧