Autor Beitrag
G-man
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Di 26.08.03 14:30 
Abend,
wie kan ich mit einer IndyKomponente (z.B. IdHttp) mehrere Downloads parallel ausführen?

_________________
...To err is human, but to really foul things up requires a computer.
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Di 26.08.03 14:32 
Hi,

die einzelnen Downloads in Threads auslagern.

MFG

- Ernesto -
G-man Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Di 26.08.03 14:34 
Wie geht das genau (habs noch nie gemacht)?

_________________
...To err is human, but to really foul things up requires a computer.
Akut-Programming
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 69

WinXP, Win2000
Delphi 7 Enterprise, Delphi 5 Prof.
BeitragVerfasst: Di 26.08.03 14:38 
Hi G-Man!

Geh doch mal suchen!! Zum Thema "Threads" findeste bestimmt was!!!

_________________
Gruß,
Akut - Programming
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Di 26.08.03 14:46 
Hi,

da mir grad landweilig ist hab ich dir ein Beispiel geschrieben:

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:
// Code für den Thread

unit DownlThread;

interface

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

type
  TDownlThread = class(TThread)
  private
    { Private declarations }
    HTTP: TIdHTTP;
  protected
    { Protected declarations }
    procedure Execute; override;
  public
    { Public declarations }
    constructor Create(CreateSuspended: Boolean);
    destructor Destroy; override;
  end;

implementation

constructor TDownlThread.Create(CreateSuspended: Boolean);
begin
  inherited Create(False);
  HTTP := TIdHTTP.Create(nil)   // HTTP-Kompo wird dynamisch erstellt
end;

destructor TDownlThread.Destroy;
begin
  HTTP.Free;
  inherited Destroy;
end;

procedure TDownlThread.Execute;
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(ExtractFilePath(ParamStr(0))+'index.htm', fmCreate);
  try
    HTTP.Get('http://www.google.de/index.htm', fs);
  finally
    fs.Free;
  end;
end;

end.


Den Thread rufst du folgendermaßen auf:

ausblenden Delphi-Quelltext
1:
TDownlThread.Create(false);					


Für jeden weiteren Download machst du das genau so.
Du solltest dich dennoch über Threads schlau machen, damit du das auch verstehst. Am besten in der Delphi-Hilfe oder auf www.delphi-source.de gibt es zu diesem Thema gute Tutorials.

MFG

- Ernesto -


Zuletzt bearbeitet von ErnestoChe am Mi 27.08.03 08:53, insgesamt 1-mal bearbeitet
G-man Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Di 26.08.03 14:51 
Vielen Dank.
Ich denke, du konntest mir helfen.

_________________
...To err is human, but to really foul things up requires a computer.
zanone
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Fr 20.08.04 20:03 
[quote="ErnestoChe"]Hi,

da mir grad landweilig ist hab ich dir ein Beispiel geschrieben:

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:
// Code für den Thread

unit DownlThread;

interface

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

type
  TDownlThread = class(TThread)
  private
    { Private declarations }
    HTTP: TIdHTTP;
  protected
    { Protected declarations }
    procedure Execute; override;
  public
    { Public declarations }
    constructor Create(CreateSuspended: Boolean);
    destructor Destroy; override;
  end;

implementation

constructor TDownlThread.Create(CreateSuspended: Boolean);
begin
  inherited Create(False);
  HTTP := TIdHTTP.Create(nil)   // HTTP-Kompo wird dynamisch erstellt
end;

destructor TDownlThread.Destroy;
begin
  HTTP.Free;
  inherited Destroy;
end;

procedure TDownlThread.Execute;
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(ExtractFilePath(ParamStr(0))+'index.htm', fmCreate);
  try
    HTTP.Get('http://www.google.de/index.htm', fs);
  finally
    fs.Free;
  end;
end;

end.




Hi,

ich hätte eine Frage zu diesem Beispielcode.
Wie kann ich die Events von IdHttp innerhalb des Threads abfangen?
z.b. OnWorkBegin etc.

Danke, Gruss
jolomino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: Fr 04.02.05 19:18 
[quote="zanone"]
ErnestoChe hat folgendes geschrieben:
Hi,

da mir grad landweilig ist hab ich dir ein Beispiel geschrieben:

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:
// Code für den Thread

unit DownlThread;

interface

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

type
  TDownlThread = class(TThread)
  private
    { Private declarations }
    HTTP: TIdHTTP;
  protected
    { Protected declarations }
    procedure Execute; override;
  public
    { Public declarations }
    constructor Create(CreateSuspended: Boolean);
    destructor Destroy; override;
  end;

implementation

constructor TDownlThread.Create(CreateSuspended: Boolean);
begin
  inherited Create(False);
  HTTP := TIdHTTP.Create(nil)   // HTTP-Kompo wird dynamisch erstellt
end;

destructor TDownlThread.Destroy;
begin
  HTTP.Free;
  inherited Destroy;
end;

procedure TDownlThread.Execute;
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(ExtractFilePath(ParamStr(0))+'index.htm', fmCreate);
  try
    HTTP.Get('http://www.google.de/index.htm', fs);
  finally
    fs.Free;
  end;
end;

end.




Hi,

ich hätte eine Frage zu diesem Beispielcode.
Wie kann ich die Events von IdHttp innerhalb des Threads abfangen?
z.b. OnWorkBegin etc.

Danke, Gruss


tja, dass mit den events würde mich auch mal interessieren, hat da evtl einer eine antwort?

und zu ErnestroChe aussage:
"Für jeden weiteren Download machst du das genau so. "
das ist mir auch noch nicht so klar. heisst das etwa, das wenn ich 20 downloads anstarten möchte, auch 20 units anlegen muss?

gruss jolomino
Basti
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: Sa 05.02.05 12:56 
jolomino hat folgendes geschrieben:

und zu ErnestroChe aussage:
"Für jeden weiteren Download machst du das genau so. "
das ist mir auch noch nicht so klar. heisst das etwa, das wenn ich 20 downloads anstarten möchte, auch 20 units anlegen muss?
gruss jolomino


Er meint damit, dass du dann 20 mal den Constructor aufrufen musst (Create).
Da du aber wahrscheinlich von verschiedenen Adressen downloadest,
würde ich dann an deiner Stelle noch den Parameter URL übergeben.

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.
jolomino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58



BeitragVerfasst: So 06.02.05 07:44 
boah, ich versteh nur bahnhof.
also, ich habe ein unit mit den oben genannten thread-code erzeugt, welches ich zum testen per button starte, ist ein einfacher download. nun möchte ich aber aus einem stringgrid zeile 1 downloaden, oder halt angeben das die ersten 3 aus dem stringgrid gleichzeitig gestarten werden sollen.
wie mache ich das nun und wie übergebe ich den thread die url?
was ist mit "20 mal den Constructor aufrufen" gemeint? brauche ich also nur ein downloadthread-unit und kann dieses jetzt 20mal aufrufen?
und zu guter letzt, wie komme ich an die IdHTTP1WorkBegin der einzelnen threads ran?

fragen über fragen, aber was wollt ihr von einem noob erwarten? :(

gruss jolomino
Basti
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 345

Windows Vista
D2005 Pers, D7 Pers
BeitragVerfasst: So 06.02.05 15:00 
Das alles zu erklären, wäre zu viel.
Also die Sache mit dem x mal erzeugen hat was mit Objektorientierung zu tun.
Lies dir dazu mal das hier durch:
www.dsdt.info/grundlagen/sprache/oo.php
Die Übergabe der URL hängt mit Prozeduren und Funktionen zusammen.
Dazu ist das hier die Erklärung:
www.dsdt.info/grundl...sprache/prozfunk.php

Vielleicht kommst du damit schon etwas weiter.
Andere Themen auf den Seiten sollten für dich auch interessant sein.

_________________
Der Computer ist die logische Weiterentwicklung des Menschen: Intelligenz ohne Moral.