How it Works

Delphi User's Guide > Mail Merge

Each of the 3 edit controls on the second form is connected to a field in the database. The data is read from the database in the same way as in the Database sample.The only new thing is copying the data from the edit controls to the text fields in the document. This is done when you click on the Insert button:

procedure TForm2.Button1Click(Sender: TObject);
   Form1.TXTextControl1.FieldCurrent := 1;
   Form1.TXTextControl1.FieldText := Form2.Edit1.Text;
   Form1.TXTextControl1.FieldCurrent := 2;
   Form1.TXTextControl1.FieldText := Form2.Edit2.Text;
   Form1.TXTextControl1.FieldCurrent := 3;
   Form1.TXTextControl1.FieldText := Form2.Edit3.Text;

To implement a real mail merge function you will have to add a dialog box in which the user can select the database to be used. You may also want to provide a variable number of database fields which are dependent on the contents of the selected database.