Autor Beitrag
hitstec
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 295



BeitragVerfasst: Do 11.09.03 23:48 
Servus,

ich versuche vergeblichst einen FTP Get Transfer im OnWork-Ereignis mit der Prozedur Abort zu terminieren. Leider hagelt es darauf nur noch Exceptions, die sich noch nicht mal abfangen lassen. Hat jemand Erfahrungen mit diesem Phänomen und/oder kann mir ein Workaround zeigen?

Bitte? So schauts aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
 FTP:=TIdFTP.Create(nil);
 try
  FTP.OnWorkBegin:=FTPOnWorkBegin;
  FTP.OnWork:=FTPOnWork;
  FTP.OnStatus:=FTPOnStatus;
.
.
  FTP.Get(...
.
.
.

procedure TSyncThread.FTPOnWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
begin
 if AWorkMode=wmRead then SyncForm.ProgressBar.Position:=SyncForm.ProgressBar.Tag+AWorkCount;
 if bClose then FTP.Abort;
end;

Nachtrag: Es ist die Indy Kompo in Delphi 6.
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Fr 12.09.03 07:22 
Kleiner Tipp zu Deinen Exceptions: in Delphi werden die trotz try, except IMMER behandelt.

Außerhalb der IDE werden sie dann wie geplant. abgefangen.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
hitstec Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 295



BeitragVerfasst: Fr 12.09.03 12:52 
Bla bla bla ...

Es hängt wohl damit zusammen, dass ich die FTP Verbindung in einem Thread erstelle. Die FTP Variable ist dabei global. Eventuell laufen beide Vorgänge (Transfer und Abbruch) nicht syncron!?

:?:
hitstec Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 295



BeitragVerfasst: Fr 12.09.03 13:05 
Jepp so ist das:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
 TSyncThread = class(TThread)
  private
  protected
   procedure Execute; override;
   procedure FTPOnWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
  end;

var Form1: TForm1; bClose: Boolean=false; FTP: TIdFTP;

implementation

{$R *.dfm}

procedure TSyncThread.Execute;
begin
 FTP:=TIdFTP.Create(nil);
 with FTP do begin
  OnWork:=FTPOnWork;
  Host:='...';
  Username:='...';
  Password:='...';
  Passive:=true;
  Connect;
  ChangeDir('...');
  Get('...','...');
 end;
 FTP.Free;
end;

procedure TSyncThread.FTPOnWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer);
begin
 if bClose then FTP.Abort;
end;

procedure TForm1.Button1Click(Sender: TObject);
var thrFtp: TSyncThread;
begin
 thrFtp:=TSyncThread.Create(true);
 thrFtp.Priority:=tpNormal;
 thrFtp.FreeOnTerminate:=true;
 thrFtp.Resume;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 bClose:=true;
end;

Wenn ich also so die Abort Prozedur aufrufe, dann meldet sich Delphi mit einer EIdProtocolReplyError Exception mit der Fehlermeldung "Broken pipe".

Hat jemand eine Idee, wie ich das umgehen kann?
hitstec Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 295



BeitragVerfasst: Fr 12.09.03 13:13 
Selbstgespräche zu führen ist zwar doof, aber das Problem lässt sich lösen, indem man die Vorgänge in OnWork syncronisiert.
Warum auch immer ?!?