Match Merge

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math Topics]   [Library]   [Utilities]

Search

 

Search DelphiForFun.org only

Support DFF

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Support DFF

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

 

 

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

 

Search DelphiForFun.org only

 

 

 

 

Problem Description

MatchMerge  merges two text files in alpha text sequence and optionally saves the merged records in a new file.  Text case is ignored,   Options are provided  to sort input files if they are not in sequence, and to eliminate duplicate records in the output file.

Background & Techniques

This started as a Beginners exercise in response to a user request but along the way a  need for a more complete program arose.  A problem with the December DFF Newsletter required me to delete the subscribers list (after downloading a copy).  Since then about 25  new users have subscribed which needed to be combined with the original list before the next newsletter can be sent.   This program has merged the lists and as a side benefit, eliminated a number of duplicate subscribed email addresses - those who hit the "Subscribe" button twice "just to be sure".

Non-programmers are welcome to read on, but may want to skip to the bottom of this page to download executable version of the program.

The merge logic uses an "GetNext" function to return the lowest record which has not yet been returned to the user for each call.  The returned integer value is "1" or "2" to indicate the source of the record (File1 or File2) or "0" to indicate that all records have been returned.   Global variables "Line1" and "Line2" are as look-ahead buffers to  used hold the next records to be compared from File1 and File2.   They are initialized with the first record from each file before the first call to GetNext.  

When the Merge button is clicked, two file names are solicited from the user.  Procedure Checkfile is called with each filename.  Checkfile makes sure that the records in the file are in ascending sequence or asks the user for permission to sort the records if not.    The program will run with unsorted files, but results will generally be unpredictable.  

The main processing loops calls the GetNext to get the next record until the return value is 0.   Each record is checked to see if it matches the last record added to the output display (Listbox3).  If so it is counted as a duplicate and either dropped or added to the list depending on whether the DupsBox checkbox is checked.   After all records have been processed, the user is asked for an output file name and list box contents written to the file if a name was provided. 

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Allow merging of more than 2 files.
Allow user to define fields on which to sort and instead of using the entire record.
Allow case sensitivity.

 

Original Date: mmm dd, yyyy 

Modified: May 18, 2009

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2013, Gary Darby    All rights reserved.