{******************************************************************}
{ InetThrd.pas                                                     }
{                                                                  }
{ Author    : A.Nasir Senturk                                      }
{ Home Page : http://www.shenturk.com                              }
{ Email     : shenturk@gmail.com                                   }
{                                                                  }
{ Date      : 28.11.2006                                           }
{                                                                  }
{ Sizden iki şey rica edicem:                                      }
{ 1. Lutfen bu baslik kismini kaldirmayiniz.                       }
{ 2. Mumkunse bagis yapiniz.                                       }
{ *****************************************************************}

unit InetThrd;

interface

uses Windows, SysUtils, Classes, WinInet, InetUtil;

type
  TInetThread = class(TThread)
  private
    { Private declarations }
    FRequest: TRequest;
    FInetHandle: HINTERNET;
    FHandle: THandle;
    FMessage: Cardinal;
  protected
    procedure Execute; override;
  public
    constructor Create(AHandle: THandle; AMessage: Cardinal;
      AInetHandle: HINTERNET);
    destructor Destroy; override;
    property Request: TRequest read FRequest;
    property Terminated;
  end;

implementation

{ 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 TInetThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ TInetThread }

constructor TInetThread.Create(AHandle: THandle; AMessage: Cardinal;
  AInetHandle: HINTERNET);
begin
  inherited Create(True);
  FHandle := AHandle;
  FMessage := AMessage;
  FInetHandle := AInetHandle;
  FRequest := TRequest.Create;
end;

destructor TInetThread.Destroy;
begin
  FRequest.Free;
  inherited Destroy;
end;

procedure TInetThread.Execute;
var
  Result: Integer;
begin
  Result := FRequest.SendRequest(FInetHandle);
  PostMessage(FHandle, FMessage, 0, Result);
end;

end.
 