Thema: Delphi Irc mit Indy

Einzelnen Beitrag anzeigen

Benutzerbild von Valle
Valle

Registriert seit: 26. Dez 2005
Ort: Karlsruhe
1.223 Beiträge
 
#12

Re: Irc mit Indy

  Alt 20. Dez 2008, 13:54
Ich habe das Tutorial mal aus gegebenem Anlass ins Englische übersetzt, damit unser User dangerduck auch was davon versteht. Ich hoffe, MSSSSM hat nichts dagegen.

---

Hello and welcome!

This post is about the Indy IRC component.

You can download it here.

Let's begin:

First, put the Indy IRC component on your form.

Form.Create should now look like the following:
Delphi-Quellcode:
IdIRC1.Nick:='MyNick'; // Defines the nickname

IdIRC1.Host:='irc.server.org'; // Defines the Server

IdIRC1.Port:=6667; //Irc Port
With this you define the settings for the connection.

Now we have to connect:

Put a button on your form and create the onClick-event:
The buttons caption should be 'Connect'

Put in this code:
Delphi-Quellcode:
try // try ...
IdIRC1.Connect(); // ... to connect
except // ... when an error happens ...
showMessage('Fehler beim Verbinden!'); // ... show a message
end;
You should make a buton with the folling code in the onClick-event
IdIRC1.Join('#lima-city'); Now you can already connect and join a channel.
But to display messages later, you should put a the TMemo component on the form.

The you have to add two events: OnReceive and OnMessage.

OnReceive (It only works with this additional event):
Memo1.lines.add(ACommand); // add to memo OnMessage:
Memo1.lines.add(AUser.Nick+': '+Content); // Add message
Now you can already receive a message, but it lacks writing yet.

Put a TEdit and a TButton component on your form.

The button gets the caption "Send".

The OnClick-event is:

Delphi-Quellcode:
IdIRC1.Say('#CHANNEL',Edit1.Text); // Send message to the channel
Memo1.Lines.Add(IdIRC1.Nick+': '+Edit1.Text); // Ad to memo, because the OnMessage event won't be called when sending own messages
Now you can send and receive messages with that.

Put the following into the forms OnClose event:

IdIRC1.Disconnect(); // to stop

Additional code:
Create a TListBox.
Create the OnNames event and write:
Delphi-Quellcode:
var
 i: integer;
//begin
for i:=0 to AUsers.Count-1 do // execute as many times as users in the channel
ListBox1.Items.Add(AUsers.Items[i].Nick); // Add to ListBox
//end
Now you have a working IRC client!

Tip: Build an IRC-bot, you only have to work with the content in OnMessage!
Valentin Voigt
BOFH excuse #423: „It's not RFC-822 compliant.“
Mein total langweiliger Blog
  Mit Zitat antworten Zitat