使用IdFTP 控件出现的问题(75)

  • 主题发起人 主题发起人 tom12345
  • 开始时间 开始时间
T

tom12345

Unregistered / Unconfirmed
GUEST, unregistred user!
在使用 if IdFTP1.DirectoryListing.Items.ItemType= ditDirectory then 这一语名时,不论 i 值为多少,都显示:  List index out of bounds (0)应如何解决?
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, IdFTPList;type TForm1 = class(TForm) Button1: TButton; IdFTP1: TIdFTP; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var i: integer;begin i := 0; //delphi7.0 indy 9.00.10 IdFTP1.DirectoryListing.Add; if IdFTP1.DirectoryListing.Items.ItemType = ditDirectory then begin showmessage('0'); end else begin showmessage('1'); end;end;end.//我这正常的
 
zhengrong117, 不会出错了,可是却不能读取文件夹及文件, 程序如下: try LS := TStringList.Create; ComboBoxftp.Text:='/'; IdFTP1.ChangeDir(ComboBoxftp.Text); listviewftp.Items.Clear; IdFTP1.List(LS); FolderCount := 0; for FileCount:=0 to LS.Count - 1 do begin IdFTP1.DirectoryListing.Add; if IdFTP1.DirectoryListing.Items[FileCount].ItemType = ditDirectory then //uses IdFTPList. begin newItem := listviewftp.Items.Insert(FolderCount); newItem.ImageIndex := 0; newItem.subItems.Add('文件夹'); end else begin newItem := listviewftp.Items.Add; newItem.ImageIndex := 2; newItem.subItems.Add(''); end ; newItem.Caption := idftp1.DirectoryListing.Items[FileCount].FileName; newItem.subItems.Add(IntToStr(idftp1.DirectoryListing.Items[FileCount].Size)); newItem.subItems.Add(DateToStr(idftp1.DirectoryListing.Items[FileCount].ModifiedDate)); end; finally LS.Free; end;
 
参考下面的代码:(我是Indy 10.0)注意要 uses IdAllFTPListParsersfunction TForm1.Done: Boolean; var tr, dtr: TStrings; I: Integer;begin ... if not IdFTP1.Connected then IdFTP1.Connect(); if IdFTP1.Connected then //如果连接成功则上传文件 begin tr := TStringList.Create; IdFTP1.List(tr); for I := 0 to IdFTP1.DirectoryListing.Count - 1 do begin if IdFTP1.DirectoryListing.Items.ItemType = ditDirectory then begin try IdFTP1.ChangeDir('P/Data');//定位到 Data 文件夹 dtr := TStringList.Create; IdFTP1.List(dtr); except on E: Exception do begin ListBox1.Items.Add(DateTimeToStr(Now) + ' ' + E.Message); WriteLogFile(E.Message); Exit; end; end; end; end; ...; end; end;
 
szhcracker, 能提供完整的源码吗?
 

Similar threads

S
回复
0
查看
896
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部