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,

Mailing lists / fpc-pascal / 2013-04
6 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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,
First of all change the order of lines 25-26
inherited Create(False);
FreeOnTerminate := True;
instead of
FreeOnTerminate := True;
inherited Create(False);The, drop the DoExecute procedure and replace it by the Execute procedure. It is useless to Synchronize a thread's procedure inside itself ! After the creation, the thread executes immediately the overriden procedure Execute because, at creation time (inherited Create(False); ) the thread is created in the state NON SUSPENDED. The use of the DoExecute is obviously useless
our program will execute the procedure Excute only once as there is no loop.
Sita Software
*Antonio Fortuny*
Senior Software engineer
220, avenue de la Liberté
L-4602 Niederkorn
Tel.: +352 58 00 93 - 93
www.sitasoftware.lu <http://www.sitasoftware.lu>
Your IT Partner
I tried to use TThread in a small sample, but it don't works. The code is very simple,…
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.That bug has been fixed long time ago.
Michael.
First of all change the order of lines 25-26 inherited Create(False); FreeOnTerminate :=…
2013/4/18 Antonio Fortuny
Thank for the explanation. ;)
Here's a version which I think should work everywhere. I think there might be a bug in…
2013/4/18 Jeppe Græsdal Johansen
Worked fine, thank you! :)