type TForm2 =
class(TForm)
...
private
MaxBytesPerSecond, WorkTime: LongWord;
CountAtLastWorkEvent: Int64;
procedure WorkEvent(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
end;
procedure TForm2.WorkEvent(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
var i: Integer;
begin
i := (AWorkCount - CountAtLastWorkEvent) * 1000
div (GetTickCount - WorkTime);
If i > MaxBytesPerSecond
Then
Sleep((GetTickCount - WorkTime) * (i - MaxBytesPerSecond)
div MaxBytesPerSecond);
WorkTime := GetTickCount;
CountAtLastWorkEvent := AWorkCount;
end;
procedure TForm2.FormCreate(Sender: TObject);
var HTTP: TIdHTTP;
temp:
String;
begin
HTTP := TIdHTTP.Create;
try
HTTP.Request.BasicAuthentication := true;
HTTP.Request.Username := Username;
HTTP.Request.Password := Password;
HTTP.HandleRedirects := true;
HTTP.OnWork := WorkEvent;
MaxBytesPerSecond := 1024;
WorkTime := GetTickCount;
CountAtLastWorkEvent := 0;
temp := HTTP.Get(
URL);
finally
HTTP.Free;
end;
end;