function Encode2(var s:WideString):String;
var 
i,len:Integer; 
cur:Integer; 
t:String; 
begin 
Result:='';
len:=Length(s); 
i:=1; 
while i<=len do 
begin 
cur:=ord(s[i]); 
//BCD转换 
FmtStr(t,'%4.4X',[cur]);
Result:=Result+t;
inc(i);
end;
end;我调用时:
memo2.text:=Encode2('40128200002A7ED962116');
报错:Constant object cannot be passed as var parameter
请问我该如何调用?

解决方案 »

  1.   

    var s:WideString -》 s:WideStringORvar 
      strTmp:  WideString;
    begin
      strTmp :='40128200002A7ED962116';
      memo2.text:=Encode2(strTmp);
    end;
      

  2.   

    qxj(游民)老大,还请帮小弟写写Encode2函数的逆函数好吗,谢谢
      

  3.   

    function DisCode1(text:String): String;
    var
      i, j, len, a, b :Integer;
    begin
      Result := '';
      len := Length(text);
      i := 1;
      j := 0;
      while (i<=len) do
      begin
        if i > 2 then
          a := StrToIntDef('$' + Copy(text, i - 2, 2), 0)
        else a := 0;
        b := StrToIntDef('$' + Copy(text, i, 2), 0);
        Result := Result + Chr((a shr (8 - j)) or (b shl j) and $7F);
        Inc(i, 2);
        j := (j + 1) mod 7;
        if j = 0 then Result := Result + Chr((b shr 1) and $7F);
      end;
    end;{DisCode1}
      

  4.   

    哇,感动呀,这么晚了qxj老大还来帮助小弟,真是感动哇,谢谢谢谢:)
      

  5.   


    function EnCode2(text:String): String;
    var
      i, len, cur :Integer;
      s :String;
    begin
      Result := '';
      i := 1;
      len := Length(text);
      while (i<=len) do
      begin
        cur := ord(text[i]);
        FmtStr(s, '%4.4X', [cur]);
        Result := Result + s;
        inc(i);
      end;
    end; {EnCode2}function DisCode1(text:String): String;
    var
      i, j, len, a, b :Integer;
    begin
      Result := '';
      len := Length(text);
      i := 1;
      j := 0;
      while (i<=len) do
      begin
        if i > 2 then
          a := StrToIntDef('$' + Copy(text, i - 2, 2), 0)
        else a := 0;
        b := StrToIntDef('$' + Copy(text, i, 2), 0);
        Result := Result + Chr((a shr (8 - j)) or (b shl j) and $7F);
        Inc(i, 2);
        j := (j + 1) mod 7;
        if j = 0 then Result := Result + Chr((b shr 1) and $7F);
      end;
    end;{DisCode1}
      

  6.   

    刚才试了,老大:)用第一个函数转PDU,再用第二个函数转STRING,但不能还原,惨了惨了,老大,请教啦,哪里有点问题呢?谢谢
      

  7.   

    function DisCode2(text:String): String;
    var
      i, len:Integer;
    begin
      Result := '';
      i := 1;
      len := Length(text);
      while (i<=len) do
      begin
        Result := Result + Chr(StrToIntDef('$' + Copy(text, i, 4), 0));
        inc(i, 4);
      end;
    end; {DisCode2}
      

  8.   

    谢谢,利用上面您提供的两个函数确实可以互相转换了,但是却不是标准的PDU码
    我用顶楼的函数转换成的PDU码和手机里读出来的PDU码才是一样的
    用您的函数转成PDU码后和从手机里读出来的PDU码不一样
    还请多多指教,谢谢
      

  9.   

    例如,我用顶楼的函数将“中国”转为PDU码为:“4E2D56FD”,和手机中取出的PDU码一致
    但您的函数转成PDU码后和手机中取出的不一致:“00D600D000B900FA”
    真不知道哪里有问题了
      

  10.   

    可以参考以下
    http://search.csdn.net/Expert/topic/879/879633.xml?temp=.231991function SMSEncode(s:WideString;Result_Code:pchar):Bool;Stdcall;export;
        function SMSDecode(Input_Code:pchar;Result_Str:pchar):Bool;Stdcall;export;