Schau dir mal try-except und try-finally an
Guckst du
hier.
Delphi-Quellcode:
procedure TFormSys.BtFTPClick(Sender: TObject);
begin
BtSpeichern.Click;
IdFTP1.Host:= '
***';
IdFTP1.Port:= (21);
IdFTP1.Username:= '
***';
IdFTP1.Password:= '
***';
try
IdFTP1.Connect;
except
on E :
Exception do
begin
LabelError.Caption := '
Could not connect to server: ' + E.
Message;
Exit;
end;
end;
try
try
IdFTP1.Put(ExtractFilePath(ParamStr(0)) +'
Systeminfos '+ GetUsername + '
.txt',
ExtractFileName('
Systeminfos '+ GetUsername + '
.txt'));
except
on E :
Exception do
begin
LabelError.Caption := '
Could not put data to server: ' + E.
Message;
end;
end;
finally
IdFTP1.Disconnect;
end;
end;
aua. Warum die verschachtelten try-except-Blöcke? Dazu nutzt man doch Exceptions, dass man genau so was nicht machen muss.
Delphi-Quellcode:
.. := Create(..);
try
try
Connect;
Put;
except
on E:
Exception do
// Ausnahmefehler behandeln
end;
finally
..Free;
end;