LCMapString-简繁体中文互换

2012-09-23 14:16:46| 分类: Delphi |举报|字号 订阅
//Simplified Chinese:简体中文;
//Traditional Chinese:繁体中文;
procedure TForm9.BitBtn3Click(Sender: TObject);
var sSource,sDest:String;
iLen:Integer;
begin
sSource:='abc China(中国农业银行)';
iLen:=System.Length(sSource);
System.SetLength(sDest,iLen);
Windows.ZeroMemory(PChar(sDest),iLen);
//LCMapString:区域字符串映射;
//LCMapString(
// Locale, {区域设置ID}
// dwMapFlags, {映射转换类型}
// lpSrcStr, {源字符串指针}
// cchSrc, {源字符串长度}
// lpDestStr, {目标字符串指针}
// cchDest {目标字符串长度}
//);
//Locale可选如下值:
// Locale_System_Default:系统默认的区域选项;
// Locale_User_Default:当前用户的区域选项;
//dwMapFlags可选如下值:
// LCMAP_Traditional_Chinese:将简体中文字符映射到繁体中文字符;
// LCMAP_Simplified_Chinese:将繁体中文字符映射到简体中文字符;
Windows.LCMapString(Locale_System_Default,LCMAP_Traditional_Chinese,PChar(sSource),iLen,PChar(sDest),iLen);
Edit1.Text:=Format('%s --> %s',[sSource,sDest]);
sSource:='臺灣地區';
iLen:=System.Length(sSource);
System.SetLength(sDest,iLen);
Windows.ZeroMemory(PChar(sDest),iLen);
Windows.LCMapString(Locale_User_Default,LCMAP_Simplified_Chinese,PChar(sSource),iLen,PChar(sDest),iLen);
Edit2.Text:=Format('%s --> %s',[sSource,sDest]);
end;
//附图: