Building an IRC Client - More Procedures
(Page 3 of 5 )
The Say() procedure enables you to send a message either to the channel or to another user:
procedure TForm1.Button2Click(Sender: TObject);
begin
idIRC1.Say(edit3.text, Memo2.Text);
Memo1.Lines.Add(IdIRC1.Nickname + ': '+Memo2.Text);
Memo2.Lines.Clear;
end;
With the following code you just display the message from the administrator:
procedure TForm1.IdIRC1AdminInfoReceived(ASender: TIdContext;
AAdminInfo: TStrings);
var
i:integer;
begin
for i:= 0 to AAdminInfo.Count-1 do begin
memo1.lines.add(AAdminInfo.Strings[i]);
end;
end;
Notice that the message is in a TStrings object. This requires us to loop through the object and then display the information contained within it in a memo.
procedure TForm1.IdIRC1Connect(Sender: TObject);
begin
Memo1.Lines.Add('Connection ok'); //this just confirms that we
are connected
end;
procedure TForm1.IdIRC1Status(ASender: TObject; const AStatus:
TIdStatus;
const AStatusText: String);
begin
memo1.Lines.Add(AStatusText);
end;
The status procedure keeps us up to date on what the client is doing.
procedure TForm1.IdIRC1Join(ASender: TIdContext; ANickname,
AHost,
AChannel: String);
begin
Memo1.Lines.Add('Join :' +AChannel+'NickName '+ANickName+' Host
'+AHost);
end;
This event is fired when a new user joins a channel. How much information you want about a user is up to you, but you can get the user's host name, the channel that the user joined and the user's nickname. I just added it all to the memo.
procedure TForm1.Memo2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
i : integer;
begin
if Key = VK_RETURN then
begin
idIRC1.Say(edit3.text, Memo2.Text);
Memo1.Lines.Add(IdIRC1.Nickname + ': '+Memo2.Text);
Memo2.Lines.Clear;
end;
end;
Next: Sending Messages >>
More Delphi-Kylix Articles
More By Leidago