// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "myTest.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
// ---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) {
}
// ---------------------------------------------------------------------------
void ResolveString(AnsiString *Source, TStringList *Aim, char *flag) {
const int Count = Source->Length();
int site = 1, Len = 0; // 当前截取的位置
AnsiString astrTemp, OutStr;
Aim->Clear();
// 测试要分解为多少各子串
for (int i = 1; i <= Count; i++)
if (*Source->SubString(i, 1).c_str() == *flag)
Len++;
// 开始攫取字符
for (int i = 0; i < Len; i++) // 数组层循环
{
for (; site <= Count; site++) // 字符层循环
{
astrTemp = Source->SubString(site, 1); // 获取一个字符
if (*astrTemp.c_str() == *flag) { /* 如果发现当前取到的为分隔符,那么条过分隔符,结束循环
并开始下一组字符串的截取 */
site++;
break;
}
OutStr = OutStr + astrTemp; // 合并成字符串
}
Aim->Add(OutStr);
OutStr = "";
}
}
void __fastcall TForm3::Button1Click(TObject *Sender) {
this->IdFTP1->Connect(L"202.117.191.165", 21);
this->IdFTP1->Username = L"lixinle";
this->IdFTP1->Password = "123456";
this->IdFTP1->Login();
this->IdFTP1->List();
TStrings* ListResult = this->IdFTP1->ListResult;
for (int i = 0; i < ListResult->Count; i++) {
this->ListView1->Items->Add();
AnsiString fileName = UTF8Decode(ListResult->operator[](i));
TStringList *T = new TStringList;
char flag = ' ';
fileName = fileName+" ";
ResolveString(&fileName, T, &flag);
MessageBox(NULL,IntToStr(T->Count).c_str(),L"提示",0);
ListView1->Items->operator[](i)->Caption = T->Strings[T->Count-1];
}
/* try {
this->IdFTP1->Put("VFWCapture.obj", "1.obj", false, 0);
this->IdFTP1->Get("1.obj", "D:/2.obj", false, 0);
}
catch (...) {
}
*/
}
// ---------------------------------------------------------------------------
void __fastcall TForm3::IdFTP1AfterPut(TObject *Sender) {
MessageBox(NULL, L"上传成功", L"提示", 0);
}
// ---------------------------------------------------------------------------
void __fastcall TForm3::ListView1SelectItem(TObject *Sender, TListItem *Item, bool Selected)
{
MessageBox(NULL,ListView1->Selected->Caption.c_str(), L"提示", 0);
}
//---------------------------------------------------------------------------