单步执行正确,而整体执行却错误!!! ( 积分: 50 )

  • 主题发起人 fengsizi
  • 开始时间
F

fengsizi

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高用们,我用DELPHI做了一个FTP下载(并删除)的小程序,完成以后:单步执行状态下,程序一点错误都没有;可整体执行状态下(即按下“执行”),却执行出错,FTP文件下的本该删除的文件夹却没有删除掉。
请问这是什么原因?
另外:一段程序,用try --except --end包装前出错,但包装后却又不出错了,又是什么原因呢?
谢谢!谢谢!
 
各位高用们,我用DELPHI做了一个FTP下载(并删除)的小程序,完成以后:单步执行状态下,程序一点错误都没有;可整体执行状态下(即按下“执行”),却执行出错,FTP文件下的本该删除的文件夹却没有删除掉。
请问这是什么原因?
另外:一段程序,用try --except --end包装前出错,但包装后却又不出错了,又是什么原因呢?
谢谢!谢谢!
 
代码贴上来看看
 
//删除文件夹及文件部分
procedure TfrmDownFiles.DelDirFiles(ADirFilesCount: integer);
var
iLoop: integer;
strSourceFlNm, strUpdatedFolder, strCurrPathName, strTempDirFiles: string;
label FreshStart;
label Final;
begin
try
strUpdatedFolder := UpdatedFolder;
FreshStart: // Label 开始
if (ADirFilesCount = 3) and(FtpClient.RetrieveCurrentDir = strTempDir) then
// strTempDir :全局变量,记录 Users目录下的文件夹
begin
// ACount 为 3 表示:文件夹中有 1 个文件夹或文件
goto Final;
end
else
begin
if ADirFilesCount <= 2 then
// ACount 为 2 表示:此文件夹中已经没有文件及文件夹
begin
// 此时,转到上级目录,删除之
strCurrPathName := FtpClient.RetrieveCurrentDir;
if strCurrPathName <> strTempDir then
begin
FtpClient.ChangeDirUp;
FtpClient.RemoveDir(strCurrPathName);
end;
end
else
begin

for iLoop := 0 to ADirFilesCount - 1do
begin
strSourceFlNm := FtpClient.DirectoryListing[iLoop].FileName;
if FtpClient.DirectoryListing[iLoop].ItemType = ditFile then
begin

strTempDirFiles := FtpClient.RetrieveCurrentDir + '/' + strSourceFlNm;
FtpClient.Delete(strTempDirFiles);
break;
end
else
if FtpClient.DirectoryListing[iLoop].ItemType = ditDirectory then
begin
if (strSourceFlNm <> '.') and(strSourceFlNm <> '..') then
begin
if strSourceFlNm = strUpdatedFolder then
continue
else
begin

strTempDirFiles := FtpClient.RetrieveCurrentDir + '/' + strSourceFlNm;
FtpClient.ChangeDir(strTempDirFiles);
FtpClient.List(nil, '*.*', true);
ADirFilesCount := FtpClient.DirectoryListing.Count;
goto FreshStart;
// 转到FRESHSTART 重新分析文件夹,执行过程
end;
end;
end;
end;
end;
FtpClient.List(nil, '*.*', true);
ADirFilesCount := FtpClient.DirectoryListing.Count;
goto FreshStart;
// 转到FRESHSTART 重新分析文件夹,执行过程
end;

Final: // 过程结束
except
end;
end;

//引用部分
procedure TfrmDownFiles.btnDelTestClick(Sender: TObject);
var
iLoop,jCount: integer;
slFileLst: TStringList;
begin
slFileLst := TStringList.Create;
if FtpClient.Connected then
begin
FtpClient.ChangeDir('users');
FtpClient.List(nil, '*.*', true);
for iLoop := 0 to FtpClient.DirectoryListing.Count - 1do
slFileLst.Add(FtpClient.DirectoryListing[iLoop].FileName);
for iLoop:=0 to slFileLst.Count - 1do
begin
if (slFileLst[iLoop] <> '.') and(slFileLst[iLoop] <> '..') then
begin
strTempDir := FtpClient.RetrieveCurrentDir + '/' + slFileLst[iLoop];
FtpClient.ChangeDir(slFileLst[iLoop]);
FtpClient.List(nil, '*.*', true);
jCount := FtpClient.DirectoryListing.Count;
DelDirFiles(jCount);
FtpClient.ChangeDirUp;
end;
end;
end;
end;

//谢谢!!
 
//删除文件夹
procedure TForm1.Button1Click(Sender: TObject);
Var
T : TSHFileOpStruct;
P:String;
begin
P:= Edit1.Text;//目录名
With Tdo
begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=Pchar(P);
pTo:=nil;
fFlags:=FOF_ALLOWUNDO+FOF_NOCONFIRMATION+FOF_NOERRORUI;//标志表明允许恢复,无须确认并不显示出错信息
hNameMappings:=nil;
lpszProgressTitle:='正在删除文件夹';
fAnyOperationsAborted:=False;
end;
SHFileOperation(T);
end;
 
可是,这些ShellApi函数不都是对本地文件操作的吗?
删除FTP上的文件可以吗?
 
各位高手们,有谁知道这是什么原因呢?
请不吝赐教!!
 
你单步执行的时候能够都起作用吗?另外出错的时候,提示的错误信息是什么呢?
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
740
DelphiTeacher的专栏
D
顶部