2008-05-02
解决Delphi的剪贴板的AsText方法乱码的问题(转)
关键字: astext、delphi
Wrong character in ClipBoard.AsText??
In Delphi, use ClipBoard unit, a common method "ClipBoard.AsText" is doing a wrong way when using non-English character. How to fix it? Look into the source code, you will find VCL use CF_TEXT to do the job (change it to CF_UNICODETEXT)!
Now we can use following code to due with the problem!
---Chinese---
使用Delphi的剪贴板的AsText方法会导致非英语出现乱码,怎么解决?改用Unicode就OK啦
mathsfan补充:好久没更新了,顺便来更新一下。
文章转自:http://blog.csdn.net/ly_liuyang/archive/2007/09/28/1804562.aspx
In Delphi, use ClipBoard unit, a common method "ClipBoard.AsText" is doing a wrong way when using non-English character. How to fix it? Look into the source code, you will find VCL use CF_TEXT to do the job (change it to CF_UNICODETEXT)!
Now we can use following code to due with the problem!
---Chinese---
使用Delphi的剪贴板的AsText方法会导致非英语出现乱码,怎么解决?改用Unicode就OK啦
procedure SetClipboardText(AStr: string);
var // SetBuffer(CF_TEXT, PChar(Value)^, Length(Value) + 1);
Data: THandle;
DataPtr: Pointer;
Size: Integer;
WStr: PWideChar;
begin
Size := Length(AStr) * 4;
WStr := AllocMem(Size);
try
// convert to Unicode
StringToWideChar(AStr, WStr, Size);
OpenClipboard(0);
EmptyClipboard;
Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);
try
DataPtr := GlobalLock(Data);
try
Move(WStr^, DataPtr^, Size);
SetClipboardData(CF_UNICODETEXT, Data);
finally
GlobalUnlock(Data);
end;
except
GlobalFree(Data);
raise;
end;
finally
CloseClipboard;
FreeMem(WStr);
end;
end;
mathsfan补充:好久没更新了,顺便来更新一下。
文章转自:http://blog.csdn.net/ly_liuyang/archive/2007/09/28/1804562.aspx
发表评论
- 浏览: 137757 次
- 性别:

- 来自: 浙江省杭州市

- 详细资料
搜索本博客
我的相册
文章配图20
共 24 张
共 24 张
最近加入圈子
最新评论
-
tomcatplugin下载地址
非常感谢!
-- by wxmfly -
哭死,丢了一部分文件
远离windows,远离病毒木马
-- by pig345 -
终于知道怎么把rails Web ...
yhb888@gmail.com 麻烦发给我一份吧。非常感谢
-- by haibinxx -
华为Smart AX MT800设置方 ...
老大可以发份你的modem的固件给我吗?谢谢!邮箱:ananzy@163.com
-- by ananzy -
终于知道怎么把rails Web ...
发给我一份啊,nif_yws@126.com
-- by nif_yws






评论排行榜