If you have ever wanted to build your own IRC client, keep reading. In this third part of a three-part article series, you will learn how to build an IRC client in Delphi from scratch, with assistance from Indy. While not all possible commands will be implemented, you will learn enough to add to and modify the code as you see fit.
Building an IRC Client - Procedures (Page 2 of 5 )
Below are the procedures used to implement the IRC client application commands. I will not explain all the procedures as most of them are blindingly obvious. Just remember that whenever you receive a list of anything, it will usually be sent in the form of Tstrings. To access information that is in a TString object we need a loop.
The first procedure deals with how to connect to an IRC network:
procedure TForm1.Button1Click(Sender: TObject);
begin
IdIRC1.Host := 'efnet.xs4all.nl';
IdIRC1.Port := 6667;
IdIRC1.Nickname := edit1.Text;//insert your nickname here
IdIRC1.Username:='JoeBlogg';
IdIRC1.AltNickname:=' JoeB';
try
idIRC1.Connect;
except
if not idIRC1.Connected then
begin
MessageDlg('Error connecting to ' + idIRC1.Host, mtError, [mbOK], 0);
Exit;
end;
end;
MessageDlg('Connected to ' + idIRC1.Host, mtInformation, [mbOK], 0);
button1.Enabled:=false;
end;
The code shows how to set your nickname, hostname and all the other important connection details for the client to connect successfully to a server. I cannot overemphasize the importance of entering a unique nickname when connecting to a server. This is the only way that an IRC network can identify you.
This procedure deals with how to handle a private message:
memo1.Lines.Add('' +AnicknameFrom+' The host'+Ahost+' To name:'+AnicknameTo+' The message '+AMessage);
end;
Basically all I did here was display the message received in a tmemo. I've included a lot of little details that you probably don't need to see, but you can decide which ones you want to display.