unit Unit2;
interface
uses
Classes, ExtCtrls, WinSock, SysUtils, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
type
TMain =
class(TThread)
IdTCPClient: TIdTCPClient;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
protected
procedure Execute;
override;
procedure Update;
public
hour1, min1, sek1, sekunden1, stime:real;
Port, time1:integer;
Host, S, nTime:
string;
constructor Create(ThreadPriority: TThreadPriority);
end;
implementation
uses Unit1;
{ Wichtig: Methoden und Eigenschaften von Objekten in visuellen Komponenten dürfen
nur in einer Methode namens Synchronize aufgerufen werden, z.B.
Synchronize(UpdateCaption);
und UpdateCaption könnte folgendermaßen aussehen:
procedure Main.UpdateCaption;
begin
Form1.Caption := 'Aktualisiert in einem Thread';
end; }
{ Main }
function SecondsToTime(wSeconds: Word): TDateTime;
var
wHours, wMin: Word;
begin
wHours := Trunc(wSeconds
div 3600);
wSeconds := wSeconds - (3600 * Trunc(wSeconds
div 3600));
wMin := Trunc(wSeconds
div 60);
wSeconds := wSeconds - (60 * Trunc(wSeconds
div 60));
Result := EncodeTime(wHours, wMin, wSeconds, 0);
end;
constructor TMain.Create(ThreadPriority: TThreadPriority);
Begin
inherited Create(false);
Priority:=ThreadPriority;
end;
procedure TMain.Execute;
begin
Timer1 := TTimer.Create(
nil);
{IdTCPClient:=TIdTCPClient.Create(nil);
with IdTCPClient do
Begin
ASCIIFilter:=false;
MaxLineLength:=16384;
ReadTimeOut:=0;
RecvBufferSize:=32768;
SendBufferSize:=32768;
end;}
with Timer1
do
Begin
Interval:=1000;
enabled:=true;
end;
Synchronize(Update);
end;
procedure TMain.Timer1Timer(Sender: TObject);
Begin
S := FormatDateTime('
hh:nn:ss', Time);
hour1:=strtoint(copy(S, 1, 2));
min1:=strtoint(copy(S, 4, 2));
sek1:=strtoint(copy(S, 7, 2));
sekunden1:=hour1*3600+min1*60+sek1;
time1:=Trunc(sekunden1-sTime);
nTime:=timetostr(secondstotime(time1));
{ try
IdTCPClient.Connect(100);
except
end; }
End;
procedure TMain.Update;
begin
Form1.caption := nTime;
end;
end.