Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   winnet download thread (https://www.delphipraxis.net/185221-winnet-download-thread.html)

drama22 22. Mai 2015 21:53


winnet download thread
 
iam using this code to download some images from web to memory stream inside activex its freezing too much when large image size i asked on the web they told me to put this code inside a thread i fail to do it any help with it ? here is the code

Delphi-Quellcode:
procedure DownloadToStream(const Url: string; ms: TMemoryStream);
var
  hSession    : HINTERNET;
  hService    : HINTERNET;
  lpBuffer    : array[0..1023] of Byte;
  dwBytesRead : DWORD;
  dwBytesAvail : DWORD;
  dwTimeOut   : DWORD;
begin
  hSession := InternetOpen('sessionname', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if not Assigned(hSession) then Exit;
  try
    hService := InternetOpenUrl(hSession, PChar(Url), nil, 0, 0, 0);
    if hService = nil then
      Exit;
    try
      dwTimeOut := 60000;
      InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut));
      if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then
      repeat
      Application.ProcessMessages;
        if not InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) then
          Break;
        if dwBytesRead <> 0 then
          ms.WriteBuffer(lpBuffer[0], dwBytesRead);
      until dwBytesRead = 0;
    finally
      InternetCloseHandle(hService);
    end;
  finally
    InternetCloseHandle(hSession);
  end;
end;

Sir Rufo 22. Mai 2015 22:56

AW: winnet download thread
 
Here is "I asked on the web"
http://stackoverflow.com/questions/3...-using-wininet

drama22 22. Mai 2015 23:24

AW: winnet download thread
 
yes here where i asked and i try to put the code on thread but fail any help

Medium 23. Mai 2015 00:59

AW: winnet download thread
 
Your code doesn't show any attempt to utilize a thread, and your problem description is entirely general at best. Where exactly is your problem?

drama22 23. Mai 2015 11:37

AW: winnet download thread
 
the thing is i dont know from where to start doing threading

Luckie 23. Mai 2015 11:40

AW: winnet download thread
 
Easies solution: Cteate a TThread object and call your function in the execute methode.

drama22 23. Mai 2015 12:01

AW: winnet download thread
 
i try to do thread like this

Delphi-Quellcode:
TDownloadThread = class(TThread)
public
  procedure Execute; override;
end;
but on thread excute what should i do

Luckie 23. Mai 2015 12:22

AW: winnet download thread
 
Make your function a methode of your thread object and call that methode.

drama22 23. Mai 2015 12:48

AW: winnet download thread
 
Zitat:

Zitat von Luckie (Beitrag 1302752)
Make your function a methode of your thread object and call that methode.

dont get it how to make my procedure a method it has parmeter to be added by other string and other ms

Delphi-Quellcode:
DownloadToStream(const Url: string; ms: TMemoryStream);
any code example will be more better

Luckie 23. Mai 2015 12:58

AW: winnet download thread
 
Add some pubic fields to your thread object for the parameters.


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:23 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz