Тема: Потоки help
Показать сообщение отдельно
  #1  
Старый 22.01.2010, 18:54
InfectedM InfectedM вне форума
Прохожий
 
Регистрация: 21.10.2007
Сообщения: 5
Репутация: 10
По умолчанию Потоки help

все походу...

Код:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,idhttp;

 type
 TMyThread = class(TThread)
  private
    FUrl: string;
  public
    constructor Create(CreateSuspended: Boolean; AUrl: string);
  protected
    procedure Execute; override;
    procedure UpdateCaption;
  end;

implementation

uses Unit1;

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

{ TMyThread }

constructor TMyThread.Create(CreateSuspended: Boolean; AUrl: string);
begin
  inherited Create(CreateSuspended);
  FUrl := AUrl;
  FreeOnTerminate := true;
end;

procedure TMyThread.Execute;
var
  http: TIdHTTP;
  str: TStringList;
begin
str := TStringList.Create();
  http := TIdHTTP.Create(nil);
  str.Text:= http.Get(FUrl);
  str.SaveToFile(inttostr(random(222))+'.html');
  http.Free;
  str.free ;
    sleep(5000);
  Synchronize(UpdateCaption);

end;

procedure TMyThread.UpdateCaption;
begin
  Form1.Memo2.Lines.Add(FUrl);
end;

end.

Admin: Учимся пользоваться тегами!
Ответить с цитированием