Home arrow Delphi-Kylix arrow Page 3 - Creating Chat Application with Borland Delphi/Indy: The Client
DELPHI-KYLIX

Creating Chat Application with Borland Delphi/Indy: The Client


In this third article in a series on building a chat application, you will learn how to build the user interface, how to create code to deal with messages sent from the server, how to send a request to the server, and more.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 26
January 09, 2006
TABLE OF CONTENTS:
  1. · Creating Chat Application with Borland Delphi/Indy: The Client
  2. · Building the User Interface
  3. · The Code – Dealing with messages sent from the Server
  4. · The TLog/TReading Classes
  5. · Sending a request to the Server

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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;


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 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials