Home arrow Delphi-Kylix arrow Page 3 - Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi
DELPHI-KYLIX

Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi


A mailing list would not be of much use if you cannot add and remove contact addresses. Therefore, in this second part of a two-part tutorial on building a mailing list application using Borland Delphi, we are going to add the capability of maintaining contact details.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 04, 2006
TABLE OF CONTENTS:
  1. · Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi
  2. · Breaking Down the Code
  3. · Creating a New Group
  4. · The Less Complicated Code Bits

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Contact Detail Maintenance into a Mailing List Program with Borland Delphi - Creating a New Group
(Page 3 of 4 )

Section two of the code checks to see if you selected the "create new group" option. If you did, an edit text box will appear waiting to take your input. Before it does anything else, it will check to see if you entered a group name and then add the group name to the database:

  if rb2.Checked then
  begin
//check that the new name is entered
  if ednewgroup.Text <> '' then begin
//add the new groupname to the groups table and get its ID
  form1.query1.Close;
  form1.query1.SQL.Text:='INSERT INTO groups (groupname) values
(:edval)';
  form1.query1.Parameters.ParamByName
('edval').Value:=ednewgroup.Text;
  form1.query1.ExecSQL;

It then runs another query using the newly created groupname to find its groupID:

  //now get the group id
  form1.query1.close;
  form1.query1.SQL.Text:='SELECT groupID from groups WHERE
groupname=:thename';
  form1.query1.Parameters.ParamByName
('thename').Value:=form2.ednewgroup.Text;
  form1.query1.Open;
  new_id:=form1.query1.fieldbyname('groupID').AsInteger;

Once it has the groupID, the next step is to insert the contact details into the contacts table and inform the user that the contact details have been added.

 //insert the new contact details...
  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('Both the new group: '+ednewgroup.Text+ ' and
contact: '+inttostr(new_id)+' has been added.');
  end

If the user has not entered a groupname, then it will display the appropriate error message and stop the code from executing:

  else
  begin
  showmessage('Please enter a groupname.');
  exit;
  end;
  end;

Next, we need to tell the program what to do if the user did not select any of the aforementioned options. If the user does not want to add the new contact to a group or if the user does not want to create a new groupname, then the program should simply add the contact details to the database and set the groupID column to zero. After doing this it should inform the user that the operation was successful:

  if not (rb1.Checked) and not (rb2.Checked) then
  begin
  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:=0;
  form1.query1.ExecSQL;
  showmessage('New contact has been added.');
  end;
  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 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials