Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 3 - Creating Chat Application with Borland Del...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Creating Chat Application with Borland Delphi/Indy: The Client
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 21
    2006-01-09

    Table of Contents:
  • Creating Chat Application with Borland Delphi/Indy: The Client
  • Building the User Interface
  • The Code – Dealing with messages sent from the Server
  • The TLog/TReading Classes
  • Sending a request to the Server

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating Chat Application with Borland Delphi/Indy: The Client - The Code – Dealing with messages sent from the Server


    (Page 3 of 5 )

    Add the following in the uses clause of the form (up in the interface section):

    jpeg,idsync,IdStreamVCL, INIFiles

    Then under the ‘type’ declaration add the following:

    TReadingThread = class(TThread)
            protected
                FConn: TIdTCPConnection;
                procedure Execute; override;
            public
                constructor Create(AConn: TIdTCPConnection); reintroduce;
            end;
    //you will recognise this bit from the server tutorial
             TLog = class(TIdSync)
            protected
                FMsg: String;
                procedure DoSynchronize; override;
            public
                constructor Create(const AMsg: String);
                class procedure AddMsg(const AMsg: String);
            end;

    Basically, these two classes work together to read any messages that get sent by the server; they then parse the messages to the relevant procedures. So any messages that are received by the client are processed by these classes first, before being sent on. They help to make sure that the main VCL thread is not used when messages are received. The TReading class reads the message first and then uses the tlog class to process the message.

    In the public section of the form add the following variables:

    port: integer;
    ip:string;

    Then in the form variables add:

    rt: TReadingThread = nil;

    In the implementation section add:

    uses mmsystem,picfrm,setup,sendfile;

    function ParseString(s : string; var str1,str2,str3: string) :
    boolean;
    var
       P1,P2 : integer;
    begin
       P1 := Pos('@',s);
       P2 := Pos(';',s);
       //Test if both delimiters are present, in the right order and
       //at least 1 char apart
       if ((P1 > 0) and (P2 > 0) and (P2 > P1) and (Abs(P2-P1) > 1))
         then begin
                str1 := Copy(s,1,P1-1);
                str2 := Copy(s,P1+1,P2-P1-1);
                str3 := Copy(s,P2+1,Length(s)-P2);
                Result := True; //valid string
              end
         else Result := False; //invalid string
    end;

    I’ve already explained what this function does in the server side tutorial, so I will not go through it here.

    constructor TLog.Create(const AMsg: String);
        begin
            FMsg := AMsg;
            inherited Create;
        end;

    More Delphi-Kylix Articles
    More By Jacques Noah


       · [i]In this third article in a series on building a chat application, you will learn...
       · Can i Donwload the source ? somwhere ?thnx
       · The code posted in this article isn't complete! Please, man! Post the complete...
       · how do you make categorys and sub categorys in the action manager.Need Help!!!
     

    DELPHI-KYLIX ARTICLES

    - 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...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT