Delphi XE3 簡訊發送問題

把手上的Delphi7自動發送簡訊系統轉到XE3,發現一直出現亂碼。
後來找到原因是IdHTTP.URL.ParamsEncode的問題,在Delphi7跟Delphi XE3處理出來的結果是不同的,於是在網路上找到一段改編自Delphi 7的版本。果然就行了!

[pascal]
function EnCode(ACode: string): string;
var
I: Integer;
Hex: string;
Code: AnsiString;
begin
Code := AnsiString(ACode);
for I := 1 to Length(Code) do
case Code[i] of
‘ ‘: Result := Result + ‘+’;
‘A’..’Z’, ‘a’..’z’, ‘*’, ‘@’, ‘.’, ‘_’, ‘-‘,
‘0’..’9′, ‘$’, ‘!’, ””, ‘(‘, ‘)’:
Result := Result + Code[i];
else
begin
Hex := IntToHex(ord(Code[i]), 2);
if Length(Hex) = 2 then
Result := Result + ‘%’ + Hex
else
Result := Result + ‘%0’ + hex;
end;
end;
end;
[/pascal]