unit MyComponent;
interface
uses
Windows, Messages, SysUtils, Classes, IdTCPServer;
type
TMyComponent =
class(TComponent)
private
FTCPServer: TIdTCPServer;
FOnExecute: TIdServerThreadEvent;
procedure DoServerExecute(AThread: TIdPeerThread);
procedure SetTCPServer(
const Value: TIdTCPServer);
{ Private-Deklarationen }
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
published
property TCPServer: TIdTCPServer
read FTCPServer
write SetTCPServer;
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Standard', [TMyComponent]);
end;
{ TMyComponent }
procedure TMyComponent.DoServerExecute(AThread: TIdPeerThread);
begin
if AThread.Connection.ReadLn(#10, 0) <> '
'
then
AThread.Connection.WriteLn('
Neue Prozedur');
end;
procedure TMyComponent.SetTCPServer(
const Value: TIdTCPServer);
begin
if Value <> FTCPServer
then
begin
if Value <>
nil then
begin
if (FTCPServer <>
nil)
and (FTCPServer.Owner = Self)
then
FTCPServer.Free;
FTCPServer := Value;
FTCPServer.FreeNotification(self);
FOnExecute := FTCPServer.OnExecute;
FTCPServer.OnExecute := DoServerExecute;
end
else
begin
if FTCPServer.Owner <> self
then
begin
FTCPServer.OnExecute := FOnExecute;
FTCPServer :=
nil;
end;
end;
end;
end;
end.