我从未使用过Indy并且正在努力学习基础知识。花了一些时间来弄清楚如何填充列表框。既然我已经完成了,我怎样才能在列表框中下载所选文件? 我试过了:
Sub deleteCol()
On Error Resume Next
Dim Coldellr As Long
Dim colval As String
Dim wbCurrent As Workbook
Dim wsCurrent As Worksheet
Dim nLastCol, i As Integer
Dim LngLp As Long
Coldellr = Sheets("Coldel").Cells(Rows.Count, "A").End(xlUp).Row 'Define LastRow
Set wbCurrent = ActiveWorkbook
Dim sh As Worksheet '@nightcrawler23
For Each sh In wbCurrent.Sheets '@nightcrawler23
Set wsCurrent = sh '@nightcrawler23
'This next variable will get the column number of the very last column that has data in it, so we can use it in a loop later
nLastCol = wsCurrent.Cells.Find("*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
'This loop will go through each column header and delete the column if the header contains "Percent Margin of Error"
For i = nLastCol To 1 Step -1
For LngLp = 1 To Coldellr
' Edit:
' removed Set here as a value is being assigned
colval = Sheets("Coldel").Range("a" & LngLp).Value
If InStr(1, wsCurrent.Cells(1, i).Value, colval, vbTextCompare) > 0 Then
wsCurrent.Columns(i).Delete Shift:=xlShiftToLeft
End If
Next i
Next sh '@nightcrawler23
End Sub
但我得到了:
[dcc32错误] FTP_Form.pas(75):E2250没有重载版本 可以使用这些参数调用的“获取”
或者我是否也需要使用savedialog?请帮我解决一下这个。 :)
答案 0 :(得分:4)
ListBox1.Selected[i]
是Boolean
。请注意,在上一行中您写道:
if ListBox1.Selected[i] then begin
现在,看看TIdFTP.Get()
方法。它有两个重载:
procedure Get(const ASourceFile: string; ADest: TStream;
AResume: Boolean = false); overload;
procedure Get(const ASourceFile, ADestFile: string; const ACanOverwrite: boolean = false;
AResume: Boolean = false); overload;
您需要提供:
我不知道你打算在哪里获得这些。据推测,文件名来自ListBox,因此它是ListBox1.Items[i]
。
您想要对下载的内容做什么?把它留在记忆中?将其保存到文件中?别的什么?您提供的目的地取决于您对这些问题的回答。
我的建议是暂时将ListBox放在一边,编写一个简单的程序,一个没有任何UI,只需从FTP服务器下载一个文件。使用本地文件名或TFileStream
将下载的内容保存到本地磁盘。检查内容是否符合预期。一旦您可以下载一个文件,您就可以将任意数量的文件下载到其他类型的目的地。
掌握了这一点后,请转到用户界面。花些时间了解ListBox控件的工作原理,如何填充它,如何从中读取字符串,如何测试选择等等。
只有当你对所涉及的所有部分有一个很好的理解,那么你应该尝试将它们放在一起。
答案 1 :(得分:0)
单程......
procedure TFTP.Button2Click(Sender: TObject);
Var
Name{, Line}: String;
begin
Name := IdFTP1.DirectoryListing.Items[ListBox1.ItemIndex].FileName;
SaveDialog1.FileName := Name;
if SaveDialog1.Execute then begin
IdFTP1.Get(Name, SaveDialog1.FileName, true);
end;
end;
答案 2 :(得分:0)
假设ListBox包含要下载的远程文件名(例如在调用TIdFTP.DirectoryListing
后来自TIdFTP.List()
属性):
procedure TFTP.Button2Click(Sender: TObject);
var
i:integer;
begin
for i := 0 to ListBox1.Items.Count - 1 do
begin
if ListBox1.Selected[i] then begin
IdFTP1.Get(ListBox1.Items[i], 'C:\Some Local Path\' + ListBox1.Items[i]);
end;
end;
end;