TIDIRC Tutorial
Written by Codes Tips on March 21, 2009 – 6:47 am -TIDIRC is a component of Indy Client, that can help you connect to an IRC server channel. You can send and receive messages in order to communicate with the server.
There are some important properties which you can use it to specify the server properties:
Host - is the IRC server where you want to connect
Nickname - your nick that will appear in the channel.
ReadTimeout - the time that application should wait until the server don’t respond, it is specified in miliseconds.
RealName - the real name that will appear in the server
Connecting to host
First you should connect to server and you should use the command:
//variable IdIRC1: TIdIRC;// IDIRC1 is a variable of TIDIRC component. //On button click IDIRC1.Connect;
ON succesfull you have an even OnConnected, where you can do something after the connection is established.
After connecting you can receive each response row from the server with the event IdIRCRaw. With this event you have the row AContent which is a string and you can parse it to take the information from the server or other things that you are interested.
You can take the messages that the other users send to the server, get the status of the channel.
Getting Channels
To get a list of channels you should use the property Channels and access the Items property.
for i:=1 to idirc1.Channels.Items.count do List[i] := idirc1.Channels.Items[i];//it's a TIDIRCChannel component
In TIDIRCChannel you will have the list of all channels and for every channel you have properties and events for handling a channel.
Some time, this property will not grab the channels correctly. Here is a function to get the channels from the host. You should put it in the IDIRCRaw event and make a list of channels. This function return a channel:
//GetChannel function function GetChannel(s:string):string; var p1:integer; aux:string; begin p1:=pos('#',s); inc(p1); aux:=''; if p1>1 then while (s[p1]<>' ')and(p1<=length(s)) do begin aux:=aux+s[p1]; inc(p1); end; GetChannel:=aux; end; //calling the channel function channel:=GetChannel(continut); channel:='#'+channel;
Joining a channel
To join a channel on a server you should use the command
IDIRC1.Join(channel);
Sending message
To send a message to one of the users that are connected to the channel
TIDIRC.Say(touser,message)
Parting a channel
TIDIRC.Part(channel,reason)
You can specify an optional string parameter, what was the reason of parting.
Kick user
Other usefull functions for TIDIRC Component:
Thread IRC
IDIRC1.IRCThread.Create(IDIRC1); IDIRC1.IRCThread.Start;
IDIRC1.IRCThread.Terminate; IDIRC1.IRCThread.Free;
Tags: borland delphi, Delphi
Posted in Delphi |
Leave a Comment
You must be logged in to post a comment.


















