我想从数据库中取出一些中文数据,然后用webbrowser做链接,怎么出现的中文都是乱码,如何解决啊procedure TMain_Form.ToolButton6Click(Sender: TObject);
var
url:widestring;
url1:string;
begin
with Exec_ADOQuery do
begin
close;
sql.Clear;
sql.Add('select top 10 * from cmppautosend order by senddt desc');
open;
url1:=FieldByName('msg').Asstring;
url:='http://127.0.01/default?seqno='+FieldByName('smsid').asstring+'&cpid=001&serviceid='+FieldByName('serviceid').asstring+'&usermpn='+FieldByName('destid').asstring+'&chargenm='+FieldByName('feeterminalid').asstring+'&subcode=&msg=';
url:=url+url1+'&linkid='+FieldByName('linkid').asstring;
memo2.Lines.Add(url); //在这里显示的中文正常
WebBrowser1.Navigate(url); //执行后在地址栏的中文全是乱码,我测试过将memo里的数据在ie地址栏上打开也出现乱码,状态一样
end;
end;
var
url:widestring;
url1:string;
begin
with Exec_ADOQuery do
begin
close;
sql.Clear;
sql.Add('select top 10 * from cmppautosend order by senddt desc');
open;
url1:=FieldByName('msg').Asstring;
url:='http://127.0.01/default?seqno='+FieldByName('smsid').asstring+'&cpid=001&serviceid='+FieldByName('serviceid').asstring+'&usermpn='+FieldByName('destid').asstring+'&chargenm='+FieldByName('feeterminalid').asstring+'&subcode=&msg=';
url:=url+url1+'&linkid='+FieldByName('linkid').asstring;
memo2.Lines.Add(url); //在这里显示的中文正常
WebBrowser1.Navigate(url); //执行后在地址栏的中文全是乱码,我测试过将memo里的数据在ie地址栏上打开也出现乱码,状态一样
end;
end;
var
I: Integer;
begin
Result := '';
if Length(DecodedStr) > 0 then
for I := 1 to Length(DecodedStr) do
begin
if not (DecodedStr[I] in ['0'..'9', 'a'..'z',
'A'..'Z', ' ']) then
Result := Result + '%' + IntToHex(Ord(DecodedStr[I]), 2)
else if not (DecodedStr[I] = ' ') then
Result := Result + DecodedStr[I]
else
begin
if not Pluses then
Result := Result + '%20'
else
Result := Result + '+';
end;
end;
end;
function UrlDecode(const EncodedStr: String): String;
var
I: Integer;
begin
Result := '';
if Length(EncodedStr) > 0 then
begin
I := 1;
while I <= Length(EncodedStr) do
begin
if EncodedStr[I] = '%' then
begin
Result := Result + Chr(HexToInt(EncodedStr[I+1]
+ EncodedStr[I+2]));
I := Succ(Succ(I));
end
else if EncodedStr[I] = '+' then
Result := Result + ' '
else
Result := Result + EncodedStr[I];
I := Succ(I);
end;
end;
end;
function HexToInt(HexStr: String): Int64;
var RetVar : Int64;
i : byte;
begin
HexStr := UpperCase(HexStr);
if HexStr[length(HexStr)] = 'H' then
Delete(HexStr,length(HexStr),1);
RetVar := 0;
for i := 1 to length(HexStr) do begin
RetVar := RetVar shl 4;
if HexStr[i] in ['0'..'9'] then
RetVar := RetVar + (byte(HexStr[i]) - 48)
else
if HexStr[i] in ['A'..'F'] then
RetVar := RetVar + (byte(HexStr[i]) - 55)
else begin
Retvar := 0;
break;
end;
end;
Result := RetVar;
end;
出错行if not (DecodedStr[I] in ['0'..'9','a'..'z','A'..'Z', ' ']) then
function UrlEncode(const DecodedStr:String;Pluses:Boolean):String;
var
I: Integer;
begin
Result:='';
if Length(DecodedStr) > 0 then
for I := 1 to Length(DecodedStr) do
begin
if not (DecodedStr[I] in ['0'..'9', 'a'..'z','A'..'Z',' ']) then
Result := Result + '%' + IntToHex(Ord(DecodedStr[I]), 2)
else if not (DecodedStr[I]=' ') then
Result:= Result + DecodedStr[I]
else
begin
if not Pluses then
Result := Result + '%20'
else
Result := Result + '+';
end;
end;
end;