谈一点吧:
1。定义一个动态字符串数组,一定要定义,否则就成了开放数组!
type
TDynamicString = Array of String;
2。翻译:
procedure dec_to_bcd(decstrlen: Shortint; bcdstrlen: Shortint; writebuff, writestr : TDynamicString)
var
Temp: Char;
i: ShortInt;
begin
for i := 0 to decstrlen do
begin
tmp := (writestr[2*i] and $0f) shl 4;
tmp := tmp + (writestr[2*i+1] and $0f);
tmp := tmp + 33;
writebuff[i] := tmp;
end; for i := bcdstrlen to decstrlen do
begin
writebuff[i] := writestr[i+bcdstrlen];
end;
end;
3.我想你肯定会!:-)---The end;
1。定义一个动态字符串数组,一定要定义,否则就成了开放数组!
type
TDynamicString = Array of String;
2。翻译:
procedure dec_to_bcd(decstrlen: Shortint; bcdstrlen: Shortint; writebuff, writestr : TDynamicString)
var
Temp: Char;
i: ShortInt;
begin
for i := 0 to decstrlen do
begin
tmp := (writestr[2*i] and $0f) shl 4;
tmp := tmp + (writestr[2*i+1] and $0f);
tmp := tmp + 33;
writebuff[i] := tmp;
end; for i := bcdstrlen to decstrlen do
begin
writebuff[i] := writestr[i+bcdstrlen];
end;
end;
3.我想你肯定会!:-)---The end;
TDynamicString = Array of String;
改为
TDynamicString = Array of Char;
不好意思--The end;
Operator not applicable to this operand type
还是在这一句:
tmp := (writestr[2*i] and $0f) shl 4;为什么?
谢谢!
或
tmp := (ord(writestr[2*i]) and $0f) shl 4;对不起!写的时候没有太用心!原谅我!---The end;
不好意思,好了的话告诉我一声!谢谢!---The end;
tmp是char,不知shl操作后是什么形的啊?
这个BCD码的问题好难啊。
谢谢。
告定了我告诉你。
改为 PChar
更合理一些!
那个地方不是数组,我是前两天的时候改程序改眼花了!
我改的那里面全是数组!
哎,你们公司是干什么的!在哪里呀!---The end;
procedure bcd_to_dec(decstrlen, bcdstrlen: shortint;
readbuff, readstr: TDynamicString);
var
i, j: shortint;
tmp: String;
begin
i := 0;
j := 0; //Pascal 不允许初始化局部变量!
//声明为字符串不用初始化 for i := 0 to bcdstrlen do
begin
if (readstr[i] <> 0) break;
FmtStr(tmp, '%02x', readstr[i]-33);
readbuff[2*i] := tmp[1];
readbuff[2*i+1] := tmp[2];
end;
for i := bcdstrlen to decstrlen do
begin
readbuff[i+bcdstrlen] := readstr[i];
end;
end;
function dec_to_bcd(s: string): string;
var
i: Integer;
j: char;
bcd: string;
begin
bcd := '';
for i := 0 to length(s) div 2 - 1 do
begin
j := chr(strtoint(s[2 * i + 1] + s[2 * i + 2]) + 33);
bcd := bcd + j;
end;
result := bcd;
end;function bcd_to_dec(bcd: string): string;
var
i: integer;
j: string;
begin
result := '';
for i := 1 to length(bcd) do
begin
j := inttostr(ord(bcd[i]) - 33);
result := result + j;
end;
end;还是万分感谢你。
受之有愧!---The end;