Autor Beitrag
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 14.07.02 12:06 
Hallo,

ich möchte, wie das z.b. bei Gnucleus oder anderen Saug-Tools der Fall ist, aus meiner Anwendung heraus ein paar Felder generieren.
z.b. Anwender startet Download, also soll in einer Liste (oder halt irgendeinem Objekt) ein neues Feld Dateiname, Downloadgeschwindigkeit, und eine Progressbar auftauchen.
Leider habe ich keine Ahnung wie man sowas macht.
Nimmt man da ein Panel als ParentControl, oder was macht am meisten Sinn ? Und wie füge ich dann die einzelnen Komponenten ein, und zwar mögichst so, dass alle in einer Reihe stehen (welche Komponenten machen hier Sinn ?)?

Danke für eure Infos,
Retnyg
retnyg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 14.07.02 13:14 
Am liebsten wäre mir wenn ich das in einem Stringgrid oder in einer ähnlichen Komponente machen könnte. Dann müsste ich nur irgendwie pro download den linecounter um eins erhöhen und die Werte in die Liste in eine neue Zeile schreiben. Nur, wie kriege ich die ProgressBar in den Grid ???
Vielleicht so irgendwie Stringgrid1.Cells[0,0].Create (New TProgressBar)?

Hilfe !

Code-Tag hinzugefügt. Marc
b.brecht
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: So 14.07.02 22:34 
Hi

hier ist ein CODE um eine Datei von einem FTP zu laden (es wird in eineer Progressbar auch der Status gezeigt):
ausblenden volle Höhe 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:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
uses 
  WinInet, ComCtrls; 

function FtpDownloadFile(strHost, strUser, strPwd: string; 
  Port: Integer; ftpDir, ftpFile, TargetFile: string; ProgressBar: TProgressBar): Boolean; 

  function FmtFileSize(Size: Integer): string; 
  begin 
    if Size >= $F4240 then 
      Result := Format('%.2f', [Size / $F4240]) + ' Mb' 
    else 
    if Size < 1000 then 
      Result := IntToStr(Size) + ' bytes' 
    else 
      Result := Format('%.2f', [Size / 1000]) + ' Kb'; 
  end; 

const 
  READ_BUFFERSIZE = 4096;  // or 256, 512, ... 
var 
  hNet, hFTP, hFile: HINTERNET; 
  buffer: array[0..READ_BUFFERSIZE - 1] of Char; 
  bufsize, dwBytesRead, fileSize: DWORD; 
  sRec: TWin32FindData; 
  strStatus: string; 
  LocalFile: file; 
  bSuccess: Boolean; 
begin 
  Result := False; 

  { Open an internet session } 
  hNet := InternetOpen('Program_Name', // Agent 
                        INTERNET_OPEN_TYPE_PRECONFIG, // AccessType 
                        nil,  // ProxyName 
                        nil, // ProxyBypass 
                        0); // or INTERNET_FLAG_ASYNC / INTERNET_FLAG_OFFLINE 

  { 
    Agent contains the name of the application or 
    entity calling the Internet functions 
  } 


  { See if connection handle is valid } 
  if hNet = nil then 
  begin 
    ShowMessage('Unable to get access to WinInet.Dll'); 
    Exit; 
  end; 

  { Connect to the FTP Server } 
  hFTP := InternetConnect(hNet, // Handle from InternetOpen 
                          PChar(strHost), // FTP server 
                          port, // (INTERNET_DEFAULT_FTP_PORT), 
                          PChar(StrUser), // username 
                          PChar(strPwd),  // password 
                          INTERNET_SERVICE_FTP, // FTP, HTTP, or Gopher? 
                          0, // flag: 0 or INTERNET_FLAG_PASSIVE 
                          0);// User defined number for callback 

  if hFTP = nil then 
  begin 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Host "%s" is not available',[strHost])); 
    Exit; 
  end; 

  { Change directory } 
  bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir)); 

  if not bSuccess then 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Cannot set directory to %s.',[ftpDir])); 
    Exit; 
  end; 

  { Read size of file } 
  if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil then 
  begin 
    fileSize := sRec.nFileSizeLow; 
    // fileLastWritetime := sRec.lastWriteTime 
  end else 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    ShowMessage(Format('Cannot find file ',[ftpFile])); 
    Exit; 
  end; 

  { Open the file } 
  hFile := FtpOpenFile(hFTP, // Handle to the ftp session 
                       PChar(ftpFile), // filename 
                       GENERIC_READ, // dwAccess 
                       FTP_TRANSFER_TYPE_BINARY, // dwFlags 
                       0); // This is the context used for callbacks. 

  if hFile = nil then 
  begin 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    Exit; 
  end; 

  { Create a new local file } 
  AssignFile(LocalFile, TargetFile); 
  {$i-} 
  Rewrite(LocalFile, 1); 
  {$i+} 

  if IOResult <> 0 then 
  begin 
    InternetCloseHandle(hFile); 
    InternetCloseHandle(hFTP); 
    InternetCloseHandle(hNet); 
    Exit; 
  end; 

  dwBytesRead := 0; 
  bufsize := READ_BUFFERSIZE; 

  while (bufsize > 0) do 
  begin 
    Application.ProcessMessages; 

    if not InternetReadFile(hFile, 
                            @buffer, // address of a buffer that receives the data 
                            READ_BUFFERSIZE, // number of bytes to read from the file 
                            bufsize) then Break; // receives the actual number of bytes read 

    if (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) then 
      BlockWrite(LocalFile, buffer, bufsize); 
    dwBytesRead := dwBytesRead + bufsize; 

    { Show Progress } 
    ProgressBar.Position := Round(dwBytesRead * 100 / fileSize); 
    Form1.Label1.Caption := Format('%s of %s / %d %%',[FmtFileSize(dwBytesRead),FmtFileSize(fileSize) ,ProgressBar.Position]); 
  end; 

  CloseFile(LocalFile); 

  InternetCloseHandle(hFile); 
  InternetCloseHandle(hFTP); 
  InternetCloseHandle(hNet); 
  Result := True; 
end;


Hier um eine Datei aus dem netz zu laden (2 Möglichkeiten); Deine Wünsche mit Speed sind ja dann einfach zu realisieren:

ausblenden volle Höhe 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:
70:
71:
72:
73:
74:
uses 
  URLMon, ShellApi; 

function DownloadFile(SourceFile, DestFile: string): Boolean; 
begin 
  try 
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
  except 
    Result := False; 
  end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
const 
  // URL Location 
  SourceFile = 'http://www.google.com/intl/de/images/home_title.gif'; 
  // Where to save the file 
  DestFile = 'c:\temp\google-image.gif'; 
begin 
  if DownloadFile(SourceFile, DestFile) then 
  begin 
    ShowMessage('Download succesful!'); 
    // Show downloaded image in your browser 
    ShellExecute(Application.Handle, PChar('open'), PChar(DestFile), 
      PChar(''), nil, SW_NORMAL) 
  end 
  else 
    ShowMessage('Error while downloading ' + SourceFile) 
end; 

// Minimum availability: Internet Explorer 3.0 
// Minimum operating systems Windows NT 4.0, Windows 95 

{********************************************************} 

{2.} 


uses 
  Wininet; 

function DownloadURL(const aUrl: string): Boolean; 
var 
  hSession: HINTERNET; 
  hService: HINTERNET; 
  lpBuffer: array[0..1024 + 1] of Char; 
  dwBytesRead: DWORD; 
begin 
  Result := False; 
  // hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); 
  hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); 
  try 
    if Assigned(hSession) then 
    begin 
      hService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0); 
      if Assigned(hService) then 
        try 
          while True do 
          begin 
            dwBytesRead := 1024; 
            InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead); 
            if dwBytesRead = 0 then break; 
            lpBuffer[dwBytesRead] := #0; 
            Form1.Memo1.Lines.Add(lpBuffer); 
          end; 
          Result := True; 
        finally 
          InternetCloseHandle(hService); 
        end; 
    end; 
  finally 
    InternetCloseHandle(hSession); 
  end; 
end;
retnyg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 15.07.02 22:27 
Titel: aha...
danke für den hinweis, allerdings erklärt mir das mein problem nicht ganz.

deiner funktion muss ich ja eine Progressbar als Parameter übergeben.
nur, wie erstelle ich eine Progressbar zur laufzeit ?
und wie sage ich ihr, sie soll in Zelle[3,0] meines Stringgrids stehen ?

mfg Retnyg
b.brecht
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 81



BeitragVerfasst: Mo 15.07.02 22:29 
wieso willst du sie zu laufzeit erstellen?
retnyg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Di 16.07.02 12:29 
also...ich habe ein downloadprogramm, das per textdatei betrieben wird.
sind in der datei 10 zeilen, so sollen 10 Einträge im Stringgrid und 10 ProgressBars per Code erstellt werden !
Da ich mehr als eine Datei gleichzeitig runterladen will, ist auch mehr als eine ProgressBar notwendig.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 16.07.02 13:22 
Eine Progressbar zur Laufzeit erstellen geht so:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Var
  NewProgress: tProgressBar;
Begin
  NewProgress := tProgressBar.Create (Self);
  With NewProgress Do
    Begin
      Parent := Self;
      {...}
    End;
End;
Gruß