delphi xe2 idftp使用乱码问题

stephenchern 2012-08-27 05:46:44
delphi xe2 idftp使用乱码问题
原来系统是delphi2007写的 利用idftp来操作ftp,使用方便 都很ok了
现在ide升级到delphi xe2 好处是delphi终于支持unicode了 但是随之带来的问题是 idftp在获取目录名称时 中文显示乱码
网络上也找了一些资料 设置了下 都不行 还敢请教下大家 谢谢。
...全文
503 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zungbin 2013-05-24
  • 打赏
  • 举报
回复
在idftp连接语句后面需要加以下代码 idftp1.iohandler.defstringencoding:=tencoding.ansi; 关键要加对地方:必须在connected后面加,否则运行出错。 网上搜来的, 我自己试过可以用. try with IdFtp do begin Username := User; Password := UserPwd; Host := HostIp; Port := HostPort; Connect(); IOHandler.DefStringEncoding := TEncoding.ANSI; Result := True; end except on E: Exception do begin //WriteError(e.Message); ShowMessage('FTP服务器连接错误,请检查设置或求助管理员!'); Result := False; end; end;
vga 2012-10-25
  • 打赏
  • 举报
回复
这个就是有问题....
stephenchern 2012-08-29
  • 打赏
  • 举报
回复
继续求解。。。。
ljklxlj 2012-08-28
  • 打赏
  • 举报
回复
我一段代码在xe下也遇到了乱码,将string 指定为ansistring就好了,在ftp下调整下编码方式或者用ansistring接受一下,在赋值看看
stephenchern 2012-08-28
  • 打赏
  • 举报
回复
还有哪位遇到过的 还请进来帮忙下啊 感激不尽
stephenchern 2012-08-28
  • 打赏
  • 举报
回复
var
i: Integer;
begin
IdFTP.ChangeDir(Dir);
IdFTP.TransferType := ftASCII;
IdFTP.List;
with IdFTP.DirectoryListing do
begin
ListItems.Clear;
for i := 0 to Count - 1 do
begin
with ListItems.Add do
begin
Caption := AnsiString(IdFTP.DirectoryListing.Items[i].FileName);
end;
end;
end;
end;

我改成这样 但是还是不行啊。。。是不是idftp哪里有encode设置? 之前有个地方设置了 也不行。
stephenchern 2012-08-27
  • 打赏
  • 举报
回复
简要代码发给大家看下 还请大家多多指教啊 谢谢。。
procedure TfrmMain.LoadListView(ListItems: TListItems; IdFTP: TIdFTP; Dir: string);
var
i: Integer;
begin
IdFTP.ChangeDir(Dir);
IdFTP.TransferType := ftASCII;
IdFTP.List;
with IdFTP.DirectoryListing do
begin
ListItems.Clear;
for i := 0 to Count - 1 do
begin
with ListItems.Add do
begin
Caption := ansitoutf8(IdFTP.DirectoryListing.Items[i].FileName);
// Caption := IdFTP.DirectoryListing.Items[i].FileName;
SubItems.Append(IntToStr(IdFTP.DirectoryListing.Items[i].Size));//获取文件大小,若是文件夹,大小为空
SubItems.Append(DateTimeToStr(IdFTP.FileDate(IdFTP.DirectoryListing.Items[i].FileName)));//获取文件日期 或者用 DateTimeToStr(IdFTP.DirectoryListing.Items[i].ModifiedDate) 也行 但是不能精确到秒
end;
end;
end;
end;

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧