Autor Beitrag
kalle
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

Alles mögliche
D7 ?
BeitragVerfasst: Di 07.10.08 21:42 
Hallo ich habe mir einen FTP Client gamacht.
Jetzt möchte ich das Problem mit dem Einfrieren entgegnen,indem ich den Upload Prozess als thread starte.
hier die unit1 (Hauptprogramm),Nur ne Demo ,die wenn sie funktioniert auf mein eigendliches Programm übertragen wird.
Das Verbinden funktioniert einwandfrei.
Drücke ich dann auf Copy (Button3) kommt der Fehler.
Ps Habe den Thread mit delphi delphi erstellt unter neu dann thread
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:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, StdCtrls, unit2;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    IdFTP1: TIdFTP;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FTPcopy:FTPCOPY;
    quelle:string;
    filename:string;
    { Private declarations }
  public


    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
//Connect
begin

quelle:='C:\mario.exe';
filename:='autoexec.alt';
if not idftp1.Connected then idftp1.Connect;
if idftp1.Connected then form1.Caption:='Connected';
end;

procedure TForm1.Button2Click(Sender: TObject);
//Disconnect
begin
if idftp1.connected then idftp1.Disconnect;
if idftp1.connected=(false)then form1.Caption:='Disconnected';
end;

procedure TForm1.Button3Click(Sender: TObject);
//Thread starten
begin
FTPcopy:=FTPCOPY.Create(true);
FTPCOPY.quelle:=quelle;
ftpcopy.filename:=filename;
FTPcopy.Resume;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.

Jetzt unit 2 der Thread
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:
48:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, StdCtrls;

type
  FTPCOPY = class(TThread)
  procedure kopieren;
  private

    { Private declarations }
  protected
    procedure Execute; override;
  public
  quelle,filename:string;
  end;

implementation
 uses unit1;
{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure FTPCOPY.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }


{ FTPCOPY }

procedure FTPCOPY.Execute;
begin
  synchronize (Kopieren);
  { Place thread code here }
end;
procedure FTPCOPY.kopieren ;
begin
unit1.Form1.idftp1.put(quelle,filename,true);//geht nicht
Form1.IdFTP1.Put('c:\databridge\start.wav','start.wav',true);//geht auch nicht
end;
end.

Hier die Fehlermeldung
Zitat:
Project Project1.exe raised exception class EAccessViolation with message'Access violation at adress 0041A264 in module'Project1.exe'.Write of adress 0000000E'.Process stopped.Use Step or Run to continue.

Es wäre schön wenn mich eine(r) aus dem Tal der Unwissenheit entführt
LG Kalli

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 07.10.08 22:14 
Bitte schreibe deinen Quelltext in die entsprechenden Tags, damit er als Delphi-Quelltext angezeigt wird ;-).
ausblenden Quelltext
1:
<span class="inlineSyntax"><span class="codecomment">{PROTECTTAG940d14e088634289324442403fae6e2b}</span></span>					

user profile iconkalle hat folgendes geschrieben Zum zitierten Posting springen:
if idftp1.connected=(false)then
Das ist falsch, "if not" wie kurz vorher ist richtig ;-).
www.michael-puff.de/...Wahrheitswerte.shtml
www.delphi-forum.de/viewtopic.php?p=503155

Dann dein weiterer Code:
user profile iconkalle hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure FTPCOPY.Execute;
begin
  synchronize (Kopieren);
  { Place thread code here }
end;
procedure FTPCOPY.kopieren ;
begin
unit1.Form1.idftp1.put(quelle,filename,true);//geht nicht
Form1.IdFTP1.Put('c:\databridge\start.wav','start.wav',true);//geht auch nicht
end;
end.
Also warum die Fehlermeldung kommt, habe ich nicht genauer angeschaut.
Denn du hast noch nicht so recht verstanden was du da eigentlich tust. ;-)

Der Code in Execute ist das was parallel zu deinem Hauptthread läuft. Wenn du jetzt auf eine Komponente der VCL zugreifen willst, dann musst du das im Kontext des Hauptthreads tun. Dafür benutzt du Synchronize, d.h. dein Hauptthread wird angehalten, damit dieser Code ausgeführt wird. Wenn jetzt aber alles, was du eigentlich im Thread machen willst, in Synchronize machen musst, dann bringt dir der Thread rein gar nichts.

TIdFTP ist keine visuelle Komponente, insofern bin ich mir nicht sicher, ob diese auch in einem Thread vielleicht einfach normal funktioniert. Warum erstellst du diese nicht einfach in Execute? Dann musst du gar nicht erst auf etwas außerhalb des Threads zugreifen.

Es gibt von den Indys TIdAntiFreeze, wenn du das auf dein Formular tust, sollte das Einfrieren behoben werden.

Ach ja: Ein sehr gutes Threadtutorial findest du hier:
www.michael-puff.de/...er/Delphi/Tutorials/
kalle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

Alles mögliche
D7 ?
BeitragVerfasst: Di 07.10.08 22:26 
Titel: Hi
Ja du hast recht voll ins schwarze.
Mit Threads kenne 0% aus.Hab den Code nur übernommen.
Also sollte ich das was in Kopieren steht einfach in den Bereich mit Execute einfügen?
Das mit dem Antifreeze klappt nicht.Es wurde mehrfach angeraten einen eigenen thread für den Upload zu machen.
Dieses erleichtert auch das weitervererbeiten der Fileliste.
Nach jedem Up oder Download soll die entsprechende Datei aus der To Do Liste gelöscht werden.
Freue mich auf antwort
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 07.10.08 22:29 
Nicht nur einfach in Execute hinein, sondern dort ein Objekt vom Typ TIdFTP selbst erstellen, denn der Zugriff auf ein Objekt im Hauptthread wird sonst nicht so einfach funktionieren.
kalle Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

Alles mögliche
D7 ?
BeitragVerfasst: Di 07.10.08 22:37 
Titel: Hi
also Objectr erstellen im Thread kannst du mal kurz nen sample reinklicken
Würd mich freuen
suche derweil
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 07.10.08 23:23 
ausblenden Delphi-Quelltext
1:
2:
3:
MyFTP := TIdFTP.Create(nil);
...
MyFTP.Free;