Zrobiłem klase wątku, cały kod itd, ale wątek można sobie tworzyć a i tak się za nic nie uruchomi. Oto kod wątku:
unit Unit2;
interface
uses
Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF}, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdEcho, StrUtils;
type
TPing = class(TThread)
private
FEcho: TIdEcho;
FSendData: String;
FRuns: Integer;
FMean: Extended;
function GetDS: integer;
protected
procedure Execute; override;
procedure EchoIt;
public
constructor CreatePing(CreateSuspended: Boolean);
destructor Destroy;override;
Property Runs: integer read FRuns;
property Mean: Extended read FMean;
property DataSize: Integer read GetDS;
Function IsTerminated: Boolean;
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 TPing.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
procedure TPing.Execute;
begin
{ Place thread code here }
repeat
begin
{Synchronize(}EchoIt{)};
MessageBox(0, 'Running','Droz', MB_OK);
end;
until Terminated;
end;
constructor TPing.CreatePing(CreateSuspended: Boolean);
var
I: byte;
S: String;
begin
inherited Create(CreateSuspended);
FEcho:=TIdEcho.Create(nil);
FEcho.Host:='192.168.58.128';
for I:=255 downto 1 do
S:=Chr(I);
S:=S+'HK';
FSendData:=strUtils.DupeString(S, 256*256);
end;
destructor TPing.Destroy;
begin
FEcho.Free;
FEcho:=nil;
inherited;
end;
procedure TPing.EchoIt;
begin
FEcho.Echo(FSendData);
FRuns:=FRuns+1;
FMean:=(FMean+FEcho.EchoTime)/2;
end;
function TPing.GetDS: integer;
begin
Result:=Length(FSendData);
end;
function TPing.IsTerminated: Boolean;
begin
Result:=Terminated;
end;
end.
a oto kod tworzenia i wywoływania:
procedure TfrmDroz.btnStartClick(Sender: TObject);
var
Thred: TPing;
begin
Thred:=TPing.CreatePing(True);
Thredz.Add(Thred);
Thred.AfterConstruction;
end;
Błąd jest w kodzie wątku/wywołania czy może gdzie indziej. Co jest źle? Może to wina delphi (7ent bez update pack)