谈一点吧:
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.   

    tmp := (writestr[2*i] and $0f) shl 4;这句不行啊,类型不匹配,该怎么转换呢?
      

  2.   

    哦,对不起,忘了,你把
    TDynamicString = Array of String;
    改为
    TDynamicString = Array of Char;
    不好意思--The end;
      

  3.   

    是否要转换一下! tmp := (Integer(writestr[2*i]) and $0f) shl 4;--The end; 
      

  4.   

    我按你的改了,又有这个提示:
    Operator not applicable to this operand type
    还是在这一句:
    tmp := (writestr[2*i] and $0f) shl 4;为什么?
    谢谢!
      

  5.   

    tmp := (Integer(writestr[2*i]) and $0f) shl 4;

    tmp := (ord(writestr[2*i]) and $0f) shl 4;对不起!写的时候没有太用心!原谅我!---The end;
      

  6.   

    下面的也一样!
    不好意思,好了的话告诉我一声!谢谢!---The end;
      

  7.   

    不行啊,说char和integer不兼容。
    tmp是char,不知shl操作后是什么形的啊?
    这个BCD码的问题好难啊。
    谢谢。
      

  8.   

    哦,还要用一个char转换。不出错了。
    告定了我告诉你。
      

  9.   

    其实,Array of Char
    改为 PChar
    更合理一些!
    那个地方不是数组,我是前两天的时候改程序改眼花了!
    我改的那里面全是数组!
    哎,你们公司是干什么的!在哪里呀!---The end;
      

  10.   

    好吧,我先翻译,可能也有错误,如果有错误的话,请告诉我,我现在有点忙,来不及给你测试。对不起了!
    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;
      

  11.   

    你好了吗?是不是我的代码有错误!--The end;
      

  12.   

    我重写了这段代码,验证结果正确。
    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;还是万分感谢你。
      

  13.   

    我翻译的时候,照猫画虎。不好!
    受之有愧!---The end;