delphi xe2 idftp使用乱码问题
原来系统是delphi2007写的 利用idftp来操作ftp,使用方便 都很ok了
现在ide升级到delphi xe2 好处是delphi终于支持unicode了 但是随之带来的问题是 idftp在获取目录名称时 中文显示乱码
网络上也找了一些资料 设置了下 都不行 还敢请教下大家 谢谢。
原来系统是delphi2007写的 利用idftp来操作ftp,使用方便 都很ok了
现在ide升级到delphi xe2 好处是delphi终于支持unicode了 但是随之带来的问题是 idftp在获取目录名称时 中文显示乱码
网络上也找了一些资料 设置了下 都不行 还敢请教下大家 谢谢。
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;
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设置? 之前有个地方设置了 也不行。
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;