Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 2 - Building Contact Detail Maintenance into a...
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  
Dedicated Servers  
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

Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi
By: Leidago
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-10-04

    Table of Contents:
  • Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi
  • Breaking Down the Code
  • Creating a New Group
  • The Less Complicated Code Bits

  • 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


    Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi - Breaking Down the Code


    (Page 2 of 4 )

    Let's break this code down. First the program checks to see if the user has entered the name and email address of the contact. If not, an appropriate error message is shown and the program stops executing:

    if (edname.text = '') or (edemail.Text = '') then begin
    showmessage('Please enter a name and email address');
    exit;
    end;

    Next the program checks to see if the user selected the "add contact to group" option. If the user did so, the program runs a query to find the groupID and assign that value to a variable called "new_id:"

    if rb1.Checked then begin
     if cb.Text <> '' then begin
     gname:=cb.Text;
    //search for the groupID of the selected groupname 
     form1.query1.Close;
     form1.query1.SQL.Text:='SELECT groupID from groups WHERE
    groupname=:thename';
     form1.query1.Parameters.ParamByName('thename').Value:=gname;
     form1.query1.Open;
    //Check if the group id is greater than 0:
      if form1.query1.FieldByName('groupID').AsInteger > 0  then
      begin
      new_id:= form1.query1.FieldByName('groupID').AsInteger;
      grpid:=true;

    You might wonder why we need the groupID. Well, the whole purpose of this code is to insert a new contact, and as you know, the contacts table in the database will need a groupID to identify what group, if any, the contact belongs to. That's why we need the groupID of the selected groupname. With the groupID found and assigned to the "new_id" variable, we now add the entire contact details to the contacts table:

    //Now insert the data into the database
      form1.query1.Close;
      form1.query1.SQL.Text:='INSERT INTO contacts (name,email,gid)
    values (:aname,:aemail,:agid)';
      form1.query1.Parameters.ParamByName
    ('aname').Value:=edname.Text;
      form1.query1.Parameters.ParamByName
    ('aemail').Value:=edemail.text;
      form1.query1.Parameters.ParamByName('agid').Value:=new_id;
      form1.query1.ExecSQL;
      showmessage('New contact has been added');
        end

    Next we need to make sure that the program knows what to do if the query does not find a groupID, or if the returned groupID value is less than one, or if the user does not select a groupname. The code below handles all these scenarios:

      else
      begin
      //the record with the selected name has not been found, set the
    groupID to zero
      new_id:=0;
      //Now insert the data into the database
      form1.query1.Close;
      form1.query1.SQL.Text:='INSERT INTO contacts (name,email,gid)
    values (:aname,:aemail,:agid)';
      form1.query1.Parameters.ParamByName
    ('aname').Value:=edname.Text;
      form1.query1.Parameters.ParamByName
    ('aemail').Value:=edemail.text;
      form1.query1.Parameters.ParamByName('agid').Value:=new_id;
      form1.query1.ExecSQL;
      showmessage('New contact has been added');
      grpid:=false;
      end;
      end
      else
      begin
    //User did not select a name...
      showmessage('Please select a group name to add the new contact
    to.'+#13#10+ 'If you do not see the group name on the list then
    create a new group name by selecting the ''Create a New Group ''
    option below.');
      exit;
      end;
      end;

    More Delphi-Kylix Articles
    More By Leidago


       · Please make sure that you use the latest version of Indy when compiling the sample...
     

    DELPHI-KYLIX ARTICLES

    - 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
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway