unit Unit66;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IDIRC, IDContext, StdCtrls, IdBaseComponent, IdComponent;
type
TForm66 =
class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type TIRC =
class(TThread)
private
IRC : TIDIRC;
FConnected : Boolean;
FMessage :
String;
procedure OnPrivateMessage(ASender: TIdContext;
const ANicknameFrom, AHost, ANicknameTo, AMessage:
String);
procedure OnStatus(ASender: TObject;
const AStatus: TIdStatus;
const AStatusText:
string);
procedure OnRaw(ASender: TIdContext; AIn: Boolean;
const AMessage:
String);
procedure WriteMessageInMemo;
public
Host, Channel,
Name : AnsiString;
Port : Word;
constructor Create(CreateSuspended:Boolean);
procedure StartIRC;
procedure SendText(Content : AnsiString);
procedure Execute;
override;
destructor Free;
end;
var
Form66: TForm66;
AIRC : TIRC;
implementation
{$R *.dfm}
constructor TIRC.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
IRC := TIDIRC.Create(
nil);
IRC.OnPrivateMessage := OnPrivateMessage;
IRC.OnStatus := OnStatus;
IRC.OnRaw := OnRaw;
end;
procedure TIRC.StartIRC;
begin
IRC.Host := Host;
IRC.Port := Port;
IRC.Username :=
Name;
IRC.Realname :=
Name;
IRC.Nickname :=
Name;
IRC.Connect;
IRC.Join(Channel);
FConnected := True;
end;
procedure TIRC.Execute;
var
ASender : TIDContext;
ANick,AHost,ANickTo,AMessage :
String;
begin
while (
not Self.Terminated)
do
begin
// if (FConnected) and (IRC.Connected) then
Sleep(25);
end;
IRC.Disconnect('
Ich hau ab!');
end;
destructor TIRC.Free;
begin
try
IRC.Free;
except
end;
inherited Destroy;
end;
procedure TForm66.Button1Click(Sender: TObject);
begin
Button1.Enabled := False;
Button2.Enabled := True;
AIRC := TIRC.Create(False);
with AIRC
do
begin
Host := '
*****.ath.cx';
Port := 6667;
Channel := '
Testchannel';
Name := '
Testuser';
StartIRC;
end;
end;
procedure TForm66.Button2Click(Sender: TObject);
begin
Button2.Enabled := False;
Button1.Enabled := True;
AIRC.Terminate;
end;
procedure TForm66.Button3Click(Sender: TObject);
begin
if Edit1.Text <> '
'
then
begin
AIRC.SendText(Edit1.Text);
Edit1.Text := '
';
end;
end;
procedure TForm66.FormDestroy(Sender: TObject);
begin
if not AIRC.Terminated
then
AIRC.Terminate;
end;
procedure TIRC.SendText(Content: AnsiString);
begin
IRC.Raw('
PRIVMSG '+'
#'+Channel+'
:'+Content);
end;
procedure TIRC.OnStatus(ASender: TObject;
const AStatus: TIdStatus;
const AStatusText:
string);
begin
FMessage := AStatusText;
Synchronize(WriteMessageInMemo);
end;
procedure TIRC.OnPrivateMessage(ASender: TIdContext;
const ANicknameFrom:
string;
const AHost:
string;
const ANicknameTo:
string;
const AMessage:
string);
begin
FMessage := ANicknameFrom +'
: '+ AMessage;
Synchronize(WriteMessageInMemo);
end;
procedure TIRC.OnRaw(ASender: TIdContext; AIn: Boolean;
const AMessage:
String);
begin
FMessage := AMessage;
Synchronize(WriteMessageInMemo);
end;
procedure TIRC.WriteMessageInMemo;
begin
if FMessage <> '
'
then
begin
Form66.Memo1.Lines.Add(FMessage);
FMessage := '
';
end;
end;
end.