unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts, ExtCtrls, ScktComp, IdBaseComponent, IdComponent,
IdIPWatch;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
lbIP: TLabel;
Label4: TLabel;
Label3: TLabel;
Label5: TLabel;
edNachricht: TEdit;
edIP: TEdit;
edNickname: TEdit;
cmdSenden: TButton;
cmdSetzen: TButton;
cmdNick: TButton;
ClientSocket1: TClientSocket;
ApplicationEvents1: TApplicationEvents;
IdIPWatch1: TIdIPWatch;
Timer1: TTimer;
Label6: TLabel;
lbNickname: TLabel;
cmdVerlassen: TButton;
Memo1: TMemo;
procedure cmdNickClick(Sender: TObject);
procedure cmdVerlassenClick(Sender: TObject);
procedure cmdSendenClick(Sender: TObject);
procedure cmdSetzenClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure delay(time:word);
procedure Timer1Timer(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var Nickname, Nachricht:
String;
{$R *.dfm}
procedure TForm1.delay(time: word);
var Start:Integer;
begin
Start:=GetTickCount;
while (GetTickCount) - (Start) <= time
do
Application.ProcessMessages;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
lbIP.Caption := IdIPWatch1.LocalIP;
// Die aktuelle IP-Adresse wird angezeigt.
cmdSenden.Enabled:= false;
cmdSetzen.Enabled:= false;
label6.Visible:=False;
lbNickname.Visible:=False;
end;
procedure TForm1.cmdNickClick(Sender: TObject);
begin
Nickname:= edNickname.Text;
//cmdSenden.Enabled:=True;
cmdSetzen.Enabled:=True;
//cmdNick.Visible:=False;
edNickName.Enabled:=False;
Label6.Visible:=True;
//lbNickname.Visible:=True;
lbNickname.Caption:= Nickname;
Label5.Visible:=False;
end;
procedure TForm1.cmdSetzenClick(Sender: TObject);
begin
ClientSocket1.Host:= '
192.168.255.123';
ClientSocket1.Port:= 55555;
ClientSocket1.Active:=True;
cmdSetzen.Enabled:= False;
edIP.Enabled:= False;
cmdSenden.Enabled:= True;
Nachricht:= edNickName.Text+'
hat den Raum betreten.';
delay(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
Form1.Show;
Memo1.Lines.Add(Socket.ReceiveText);
end;
procedure TForm1.cmdSendenClick(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (edNachricht.Text<>'
')
then
CLientSocket1.Socket.SendText(Nickname+'
: '+edNachricht.Text);
edNachricht.Text := '
';
end;
procedure TForm1.cmdVerlassenClick(Sender: TObject);
begin
ClientSocket1.Socket.SendText(edNickName.Text+'
hat den Raum verlassen.');
delay(500);
ClientSocket1.Close;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
lbIP.Caption:= IdIPWatch1.LocalIP;
end;
end.