Den 18-04-2013 07:03, silvioprog skrev:
Hi,

I tried to use TThread in a small sample, but it don't works. The code is very simple, and I'm sending it in attached.

Thanks,

--
Silvio Clécio
My public projects - github.com/silvioprog <http://github.com/silvioprog>

Here's a version which I think should work everywhere. I think there might be a bug in the fphttpclient code. If you don't pass the / at the end of the URI it will crash inside the getserverurl function.

program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  FPHTTPClient;

type

  { THTTPClientThread }

  THTTPClientThread = class(TThread)
  protected
    procedure Execute; override;
  public
    constructor Create;
  end;

  { THTTPClientThread }

  constructor THTTPClientThread.Create;
  begin
    inherited Create(False);
    FreeOnTerminate := True;
  end;

  procedure THTTPClientThread.Execute;
  var
    VResult: TStringList;
    VHttp: TFPHTTPClient;
  begin
    VHttp := TFPHTTPClient.Create(nil);
    VResult := TStringList.Create;
    try
      VHttp.Get('http://silvioprog.com.br/', VResult);
      VResult.SaveToFile('OUT.TXT')
    finally
      VResult.Free;
      VHttp.Free;
    end;
  end;

var Thread: THTTPClientThread;
begin
  Thread := THTTPClientThread.Create;
  Thread.WaitFor;
end.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to