home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 November / Chip_2002-11_cd1.bin / zkuste / delphi / kompon / d3456 / ICQ.ZIP / ICQ / VerySimpleExample / Main.pas < prev    next >
Pascal/Delphi Source File  |  2002-07-15  |  3KB  |  96 lines

  1. unit Main;
  2. {(C) Alex Demchenko(alex@ritlabs.com)}
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Classes, Forms, Controls, StdCtrls,
  8.   ICQWorks,       //Unit with all constants and some nifty functions
  9.   ICQClient;      //Unit with component
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     GroupBox1: TGroupBox;
  14.     PasswordEdit: TEdit;
  15.     UINEdit: TEdit;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     LoginBtn: TButton;
  19.     GroupBox2: TGroupBox;
  20.     DestUINEdit: TEdit;
  21.     Label3: TLabel;
  22.     MessageMemo: TMemo;
  23.     SendMsgBtn: TButton;
  24.     GroupBox3: TGroupBox;
  25.     EventMemo: TMemo;
  26.     ICQClient1: TICQClient;
  27.     procedure LoginBtnClick(Sender: TObject);
  28.     procedure ICQClient1Login(Sender: TObject);
  29.     procedure SendMsgBtnClick(Sender: TObject);
  30.     procedure ICQClient1ConnectionFailed(Sender: TObject);
  31.     procedure ICQClient1MessageRecv(Sender: TObject; Msg, UIN: String);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     { Public declarations }
  36.   end;
  37.  
  38. var
  39.   Form1: TForm1;
  40.  
  41. implementation
  42.  
  43. {$R *.dfm}
  44.  
  45. procedure TForm1.LoginBtnClick(Sender: TObject);
  46. begin
  47.   //Check if Password & UIN was set
  48.   if (StrToInt(UINEdit.Text) = 0) or (PasswordEdit.Text = '') then
  49.   begin
  50.     MessageBox(0, 'Please set your UIN & Password', 'Could not login', MB_ICONERROR);
  51.     Exit;
  52.   end;
  53.   //Theese parameters can be set in Properties tab of TICQClient component
  54.   ICQClient1.ConvertToPlaintext := True;          //Convert RTF text to plain (when you don't use TRichEdit)
  55.   ICQClient1.ICQServer := 'login.icq.com';        //Default login server
  56.   ICQClient1.ICQPort := 5190;                     //Default login port
  57.   ICQClient1.Password := PasswordEdit.Text;       //Set password
  58.   ICQClient1.UIN := StrToInt(UINEdit.Text);       //Set UIN
  59.   {-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-}
  60.   ICQClient1.Login;                               //Login to server!
  61.   EventMemo.Lines.Add('Connecting to server...'); //Add a line showing that we've started connection to the server
  62. end;
  63.  
  64. //This event called on a successfull logon
  65. procedure TForm1.ICQClient1Login(Sender: TObject);
  66. begin
  67.   EventMemo.Lines.Add('Successfull logon! Try to send a message to someone now!');
  68. end;
  69.  
  70. //This event called when connection with ICQ server lost or you cannot login in different reasons
  71. procedure TForm1.ICQClient1ConnectionFailed(Sender: TObject);
  72. begin
  73.   EventMemo.Lines.Add('Connection with ICQ server failed');
  74. end;
  75.  
  76. //Called when TICQClient cannot connect to specified host(login.icq.com), possible wrong login host or network is down
  77. procedure TForm1.SendMsgBtnClick(Sender: TObject);
  78. begin
  79.   //If we are online then send a message, otherwise show message requireing a login
  80.   if (not ICQClient1.LoggedIn) then
  81.   begin
  82.     MessageBox(0, 'Please, login before sending a message', 'Could not send message', MB_ICONERROR);
  83.     Exit;
  84.   end;
  85.   //Finally send the message
  86.   ICQClient1.SendMessage(StrToInt(DestUINEdit.Text), MessageMemo.Text);
  87. end;
  88.  
  89. //This event called when someone sends you a message
  90. procedure TForm1.ICQClient1MessageRecv(Sender: TObject; Msg, UIN: String);
  91. begin
  92.   EventMemo.Lines.Add('You received a message from ' + UIN + ': ' + Msg);
  93. end;
  94.  
  95. end.
  96.