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
请问我该如何调用?
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
请问我该如何调用?
strTmp: WideString;
begin
strTmp :='40128200002A7ED962116';
memo2.text:=Encode2(strTmp);
end;
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}
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}
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}
我用顶楼的函数转换成的PDU码和手机里读出来的PDU码才是一样的
用您的函数转成PDU码后和从手机里读出来的PDU码不一样
还请多多指教,谢谢
但您的函数转成PDU码后和手机中取出的不一致:“00D600D000B900FA”
真不知道哪里有问题了
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;