unit delchat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, ScktComp, ExtCtrls, StdCtrls, IdBaseComponent,
IdComponent, IdIPWatch;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Timer1: TTimer;
ClientSocket1: TClientSocket;
ApplicationEvents1: TApplicationEvents;
IdIPWatch1: TIdIPWatch;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Delay(time: word);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Nickname,Nachricht:
string;
implementation
{$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
Label6.Caption:=IdIPWatch1.LocalIP;
//Damit oben im Fenster schon beim FormCreate die aktuelle IP-Adresse angezeigt wird
Button1.Enabled:=false;
//Damit man nicht schon vorher draufdrückt
Button2.Enabled:=false;
// -''-
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Nickname:=Edit3.Text;
Button3.Enabled:=false;
Edit3.Enabled:=false;
Button2.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Host:=Edit2.Text;
ClientSocket1.Active:=true;
Button2.Enabled:=false;
Edit2.Enabled:=false;
Button1.Enabled:=true;
Nachricht:=Edit3.Text+'
hat den Raum betreten';
delay(500);
ClientSocket1.Socket.SendText(Nachricht);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (ClientSocket1.Active=true)
and (Edit1.Text<>'
')
then
ClientSocket1.Socket.SendText(NickName+'
: '+Edit1.Text);
Edit1.Text:='
';
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label6.Caption:=IdIPWatch1.LocalIP;
end;
end.