unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IDIRC, IDContext, StdCtrls;
type
TForm1 =
class(TForm)
Memo1: TMemo;
procedure ReceiveIRC(ASender: TIdContext;
const ANicknameFrom, AHost, ANicknameTo, AMessage:
String);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
type TIRC =
class(TThread)
private
FConnected : Boolean;
public
IRC : TIDIRC;
Host : AnsiString;
Port : Word;
constructor Create(CreateSuspended:Boolean);
procedure StartIRC(Channel,MyName : AnsiString);
procedure Execute;
override;
destructor Free;
end;
var
Form1: TForm1;
IRC : TIRC;
implementation
{$R *.dfm}
constructor TIRC.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
IRC := TIDIRC.Create(
NIL);
Host := '
myserver';
Port := 6667;
end;
procedure TIRC.StartIRC(Channel, MyName : AnsiString);
begin
IRC.Host := Host;
IRC.Port := Port;
IRC.Username := MyName;
IRC.Realname := MyName;
IRC.Nickname := MyName;
IRC.OnPrivateMessage := Form1.ReceiveIRC;
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
//Wie lese ich hier die Daten (/hole sie ab), wenn etwas ankommt, so, dass OnPrivateMessage aufgerufen wird?
end;
end;
destructor TIRC.Free;
begin
try
IRC.Free;
except
end;
inherited Destroy;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Channel, MyName : AnsiString;
begin
IRC := TIRC.Create(false);
Channel := '
channel';
MyName := '
User001';
IRC.StartIRC(Channel,MyName);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
IRC.Free;
end;
procedure TForm1.ReceiveIRC(ASender: TIdContext;
const ANicknameFrom:
string;
const AHost:
string;
const ANicknameTo:
string;
const AMessage:
string);
begin
if AMessage <> '
'
then
Memo1.Lines.Add(AMessage);
end;