鱼C论坛

 找回密码
 立即注册
查看: 2636|回复: 0

delphi页面乱码问题如何解决

[复制链接]
发表于 2012-7-20 16:05:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
delphi 页面是ANSI编码  mysql数据库全是utf8   如何使页面和数据库的编码保持一致? 我在页面添加信息到数据库中的中文显示正常  
你是指网页上还是Delphi上显示乱码,网页上的话也要设置相应页面为UTF8,
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

如果是DELPHI上要显示uft8的话,取出的内容用函数转换下
function unicode2gb( unicodestr:string):string;
var
  SourceLength:integer;
  DoneLength:integer;
  AscNo:integer;
  Byte1,Byte2,Byte3:integer;
  GbStr:string;
begin
result:='';
  if Trim(unicodestr)='' then exit;

  SourceLength:=Length(UnicodeStr);
  DoneLength:=1;
  repeat
  AscNo:=ord(UnicodeStr[DoneLength]);
  case (AscNo and $E0) of
  $E0:begin
     Byte1:=(AscNo and $0f) shl 12;
     Inc(DoneLength);
     if DoneLength>SourceLength then break;
     AscNo:=ord(UnicodeStr[DoneLength]);
     Byte2:=(AscNo and $3f) shl 6;
     Inc(DoneLength);
     if DoneLength>SourceLength then break;
     AscNo:=ord(UnicodeStr[DoneLength]);
     Byte3:=AscNo and $3f;
    end;
  $C0:begin
     Byte1:=(AscNo and $1f) shl 6;
     Inc(DoneLength);
     if DoneLength>SourceLength then break;
     AscNo:=ord(UnicodeStr[DoneLength]);
     Byte2:=(AscNo and $3f);
     Byte3:=0;
    end;
  0..$bf:begin
     Byte1:=AscNo;
     Byte2:=0;
     Byte3:=0;
    end;
  end;  //case;
   GbStr:=GBStr+widechar(Byte1+Byte2+Byte3);
   Inc(DoneLength);
   if DoneLength>SourceLength then break;
until DoneLength>SourceLength;
result:=GbStr;
end;


不麻烦呀,函数你复制我上面写的这个就行了。你输出时调用下就行了。比如你Delphi上定义两变量,s1,s2;取的内容先放到一个变量s1上,显示时输出S2,用我的函数调用下就行了,
var
  s1,s2 : string;
begin
  s2 := unicode2gb(s1);
end;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 05:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表