Home arrow Delphi-Kylix arrow Page 5 - Building an IRC Client
DELPHI-KYLIX

Building an IRC Client


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.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
January 22, 2007
TABLE OF CONTENTS:
  1. · Building an IRC Client
  2. · Procedures
  3. · More Procedures
  4. · Sending Messages
  5. · Processing Server Commands

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building an IRC Client - Processing Server Commands
(Page 5 of 5 )

This event handler processes every single command that comes from the server.

procedure TForm1.IdIRC1ServerListReceived(ASender: TIdContext;

  AServerList: TStrings);

 var

  i:integer;

begin

for i:= 0 to AServerList.Count-1 do begin

memo1.lines.add(AServerList.Strings[i]);

end;

end;

This event is fired when you receive a list of server names.

procedure TForm1.IdIRC1ServerWelcome(ASender: TIdContext;

  AWelcomeInfo: TStrings);

var

  i:integer;

begin

for i:= 0 to AWelcomeInfo.Count-1 do begin

memo1.lines.add(AWelcomeInfo.Strings[i]);

end;

end;

procedure TForm1.IdIRC1ServerVersion(ASender: TIdContext;
Version, Host,

  Comments: String);

begin

memo1.Lines.Add(Version +'Host '+Host+'Comments '+Comments);

end;

procedure TForm1.Edit2Click(Sender: TObject);

begin

button1.Enabled:=true;

end;

procedure TForm1.Edit3Click(Sender: TObject);

begin

button1.Enabled:=true;

end;

procedure TForm1.IdIRC1MOTD(ASender: TIdContext; AMOTD:
TStrings);

var

  i:integer;

begin

for i:= 0 to AMOTD.Count-1 do begin

memo1.lines.add(AMOTD.Strings[i]);

end;

end;

procedure TForm1.IdIRC1UserInfoReceived(ASender: TIdContext;

  AUserInfo: TStrings);

var

  i:integer;

begin

for i:= 0 to AUserInfo.Count-1 do begin

memo1.lines.add(AUserInfo.Strings[i]);

end;

end;

procedure TForm1.Button3Click(Sender: TObject);

begin

 idIRC1.Join(edit3.text);

//after joining you can request the names of the channels here,
using the ListChannel() //function and then displaying the names
in a memo.

end;

procedure TForm1.IdIRC1NicknamesListReceived(ASender: TIdContext;

  AChannel: String; ANicknameList: TStrings);

var

  i:integer;

begin

memo1.Lines.Add('Nicknames in Channel: '+AChannel);

for i:= 0 to ANicknameList.Count-1 do begin

memo1.lines.add(ANicknameList.Strings[i]);

end;

end;

This event fires when you receive a list of nicknames in a channel. The list itself is returned by the ListChannelNicknames() procedure. You also get other info such as the channel name.

procedure TForm1.IdIRC1ServerUsersListReceived(ASender:
TIdContext;

  AUsers: TStrings);

var

  i:integer;

begin

for i:= 0 to AUsers.Count-1 do begin

memo1.lines.add(AUsers.Strings[i]);

end;

end;

procedure TForm1.IdIRC1NicknameError(ASender: TIdContext; AError:
Integer);

begin

//here you get the error number(stored in AError above) and find
the error that corresponds to the number.

end;

The last three procedures just make the GUI fun by setting the progress bar position whenever the client does any work.

procedure TForm1.IdIRC1Work(ASender: TObject; AWorkMode:
TWorkMode;

  AWorkCount: Integer);

begin

 progb.Position:=AWorkCount;

end;

procedure TForm1.IdIRC1WorkBegin(ASender: TObject; AWorkMode:
TWorkMode;

  AWorkCountMax: Integer);

begin

progb.Max:=AWorkCountMax;

end;

procedure TForm1.IdIRC1WorkEnd(ASender: TObject; AWorkMode:
TWorkMode);

begin

progb.Position:=progb.Max;

end;

Below is a screen shot of the client in action:

Conclusion

I've shown you all the commands that this client application will implement. It is by no means all of the commands available, but it should give you the basis and inspiration to continue working through all the remaining commands.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials