[Demos] Mail Merge

Demos, code samples. Only questions related to the existing topics are allowed here.
Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Demos] Mail Merge

Post by Sergey Tkachenko » Sun Aug 28, 2005 11:19 am

Information about and comparison of TRichView mail merge demos.
2 of them are included in demo projects, others are available as separate
downloads.

Comparison Chart for TRichView Mail Merging Demos

Demos\Delphi\Assorted\Fields\MailMerge\
  • all fields are text items of some special text style (with the specified index);
  • fields are text items; both initial visible text of these items and tags of these items are set to field name; but visible text is not important;
  • tags will be used as field names;
  • the template editor does not save collection of styles in template documents (right-click the template editor's TRichViewEdit, choose "Settings" in the context menu. You'll see that properties are set to "Use a predefined set of styles"). So all text formatting in document is defined at design time, in RVStyle.TextStyles collection
  • the template editor's RVStyle and the main application's RVStyle have the same TextStyles collections but with one exception: the style for fields. In the template editor's RVStyle, it has a font allowing to see that it is a field clearly, in the main application's RVStyle it looks like a normal text. So, then template document is loaded, fields look like a normal text
  • FillFields procedure searches for text item with non-empty tags, and processes them as fields (changes their visible text). You can see limitations of this method:
    • field value is one line of plain text;
    • you cannot define a font of field value text in the template.
    This demo can be modified. You can set "Allow adding styles dynamically mode", and use any text styles for fields (they will be recognized by tags).
    You can use their visible text to make them look like fields (for example, it can be <<Field Name>>) and protection to disallow editing them.
Demos\Delphi\Assorted\Fields\MailMerge2\
  • all fields are text items of some special text style (with the specified index); but it's easy to modify this demo: fields can be recognized by tags, or by special properties (protection); this is because the style itself is not important - field will be deleted at the process of mailmerge;
  • this demo does not use tags
  • template editor saves collections of styles in template documents (right click the template editor's TRichViewEdit, choose "Settings" in the context menu. You'll see that the properties are set to "Allow adding styles dynamically"). This allows to add your own styles, implementing commands like "Bold", "Font", using RichViewActions, etc.
  • ReplaceFields deletes fields and inserts field values at their place; during this process, not only styles of the template are used, but also styles from documents representing field values.
    You can see limitations of this method: fields are deleted at the process of mailmerge; if you need to perform this procedure for the second time, you need to reload template.
    But this is the only method allowing to have arbitrary documents as field
    values.
http://www.trichview.com/support/files/mailmerge3.zip
  • Field values are multiline text.
    Works absolutely like MailMerge2, but field values are text, not RVF.
    Has limitations of both MailMerge and MailMerge2, but simpler than
    MailMerge2.
http://www.trichview.com/support/files/ ... elitem.zip
  • fields are not text, but special "label item"; label-items show read-only one line of text, unwrappable;
  • field name is stored in tags; initial text of label-items is not important;
  • you can use "Allow adding styles dynamically" mode with all its bonuses (not shown in this demo);
  • FillFields procedure searches for label items, reads their tags and changes their text; font of "label-items" is not changed, so you can define it in the template editor.
  • Limitations:
    • field values - one line of text
There is an advanced version of this demo in Demos\Delphi\Assorted\Fields\MailMerge-LabelItems\

http://www.trichview.com/support/files/ ... estyle.zip
  • It's like Demos\Delphi\Assorted\Fields\MailMerge\ demo, but does not use a fixed set of styles.
    Styles for fields are created on the fly, so fields can have different fonts.
http://www.trichview.com/support/files/ ... e-text.zip
  • This demo is the same as in Demos\Delphi\Assorted\Fields\MailMerge\, but fields are defined as text between { }
Read also comments at the beginning of the these demos' main form units.

--
Updates
2008-Dec-11: for compatibility with TRichView 11 and Delphi 2009.
2011-Oct-2: for compatibility with TRichView 13.4
Last edited by Sergey Tkachenko on Sun Oct 02, 2011 7:20 pm, edited 6 times in total.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Dec 01, 2005 4:22 pm

http://www.trichview.com/support/files/ ... -text2.zip

Almost the same as mailmerge-text.zip demo, but generates one multipage report instead of individual reports for each records.
Template editor and report generator are combined in one application.

Field codes: text in {}, for example {NAME}.
Field values: single line text.
--
2008-Dec-11: updated for compatibility with TRichView 11 and Delphi 2009
Last edited by Sergey Tkachenko on Thu Dec 11, 2008 1:55 pm, edited 2 times in total.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Sun Oct 22, 2006 12:05 pm

http://www.trichview.com/support/files/ ... -text3.zip

The same as mailmerge-text2.zip, but allows multiline field values.

Field codes: text in {}, for example {NAME}.
Field values: multiline text.

Note: the same function for inserting multiline text is used in the scripting demo, http://www.trichview.com/forums/viewtopic.php?t=9

2008-Dec-11: updated for compatibility with TRichView 11 and Delphi 2009

http://www.trichview.com/support/files/ ... ext3-2.zip
The same demo, but field codes are identifiers started from $, for example $NAME.
Last edited by Sergey Tkachenko on Wed Jun 15, 2011 6:35 pm, edited 1 time in total.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue May 05, 2009 1:37 pm

http://www.trichview.com/support/files/ ... -text4.zip

The same as mailmerge-text3.zip, but supports several types of field values.

Field codes: text in {}, for example {NAME}.
Field values: multiline text / picture / table / arbitrary document (RVF)

2015-Mar-26: update, RVF field type is added
Last edited by Sergey Tkachenko on Wed Mar 25, 2015 10:41 pm, edited 1 time in total.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Aug 06, 2009 4:36 pm

http://www.trichview.com/support/files/georeport.zip

Field codes: arbitrary fragment.
Field codes: arbitrary fragment.

By functionality, this demo is similar to Demos\Delphi\Assorted\Fields\MailMerge2\, but has an important advantage: new field values can be applied without template reloading (old field values can be replaced with new field values).

In this demo, a field is a set of adjacent items (of any type) marked with the same code. Field code is stored in items tags, in the form "Code|" for normal items, or "Code|Target" for hyperlinks.

This demo supports two sources of field values:
1) an arbitrary document stored in RVF format in TBlobField
2) a single line text stored in TStringField.

This demo consists of 2 projects:
- DataEdit: editing database of field values;
- GeoReport: the main applications.
The applications use a Paradox table, so BDE must be installed.

Exe-demo:
http://www.trichview.com/support/files/ ... rt-exe.zip
Showing field codes:
Image
Showing field values:
Image

Sample data were taken from wikipedia.
---
Versions:
http://www.trichview.com/support/files/ ... t_v1_1.zip . In this version, text styles for text fields are not hard-coded. The font of source text (field code) is used, only colors are changed to black-on-white (more exactly, clWindowText on transparent)

---
Changes:
2010-Oct-21: fix related for using tags in field text (hyperlinks)
2011-Oct-2: update for compatibility with TRichView 13.4
2014-Mar-13: update for compatibility with TRichView 14.x
Last edited by Sergey Tkachenko on Thu Mar 13, 2014 9:51 am, edited 4 times in total.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Jun 17, 2010 2:51 pm

In the demos above, when the field value is a multiline plain text, this value cannot contain tab characters.

To fix this problem, replace InsertMultilineText function in these demos to the function from this file:
http://www.trichview.com/support/files/ ... thtabs.zip

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Wed Oct 13, 2010 8:40 am

Master-details demo:
http://www.trichview.com/support/files/ ... detail.zip

This demo, like mailmerge-text4.zip, supports multiline text and picture fields. Fields are defined as text inside {}.
The main difference:this demo supports a master-detail relationship.
A template in this demo may contain tables linked to datasets. Such tables have a repeated group of rows; they are repeated as many times as many records in the linked dataset. If such table is inserted in a repeated row of another table, a master-detail relationship is established. Tables can be nested on any depth. The demo shows 3 levels of tables.
The demo uses Paradox tables, so BDE is required.
Image
Detailed comments are at the beginning of the main form's unit.
---
2010-Oct-13: 0 matched records in a detail table is processed correctly.

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Fri Jul 13, 2012 7:41 am

Protect-fields demo:
http://www.trichview.com/support/files/ ... fields.zip

This demo does not actually make a mail merging.
It shows how to protect text fields.
When the user clicks on the "Protect" button, it searches for all occurrences of text inside {} and apply a special (protected) style to them.

This feature is useful, for example, if you want to have fields protected and store documents in RTF.

walterfred
Posts: 2
Joined: Mon Jan 21, 2008 10:23 pm

mailmerge_text4

Post by walterfred » Tue Jun 16, 2015 12:22 pm

Hello, Sergey,

On the procedure InsertRVF, the Pos parameter is not passed as "var". At the end of the procedure, a new value is assigned to this parameter, but not used. So I think this parameter should be a var parameter, as in:

procedure TForm1.InsertRVF(RVData: TCustomRVData;
var ItemNo: Integer; var Pos: Integer; Stream: TStream);

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Jun 16, 2015 7:32 pm

In which demo?

walterfred
Posts: 2
Joined: Mon Jan 21, 2008 10:23 pm

mailmerge_text4

Post by walterfred » Tue Jun 16, 2015 7:45 pm

I've put it on the "Subject": mailmerge_text4. ;)

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Jun 16, 2015 7:46 pm

Sorry :)
I'll check it later in this week.

icehouse
Posts: 3
Joined: Tue Jan 12, 2010 9:29 pm
Location: Essen

How to merge 2 different e-mails with 2 different layouts?

Post by icehouse » Wed Jul 15, 2015 5:30 pm

Dear Sergey,
I am writing on an e-mail program for some time. It is working fine but I have problems to merge e-mails with 2! different e-mail layouts if I want to reply to an received e-mail. I spend a lot of time to achive this but I am not satisfied about the result...

The original e-mail has its own styles. As you know this is sometimes with CSS, sometimes inline CSS, sometimes direct html tags.

The standard reply layout may contain different fonts, colors and styles in inline CSS (I am using trichviewedit for this with rvhtmlviewimport)

In the beginning I replaced just the placeholder (originalmail) with the complete e-mail. Of course any layout was either lost or the layout was used from the reply layout...

Furthermore this has to be possible without creating trichtview on a form. Somehow this is crashing as soon as I call Richview.format beause the scrollbars seem to generate a problem as the need an owner which is nothing.
The function should do:
1. read orginal email as html with images (provided as streams. At the moment I am using thtmlviewer...)
2. SaveRVFToStream
3. read layout of reply with images
4. merge RVF with previous RVF stream
5. return new RVF stream with images.

Do you have an example for this case or maybe have an idea on how to do this easier?

Many thanks in advance!

Sergey Tkachenko
Site Admin
Posts: 13579
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Wed Jul 15, 2015 5:53 pm

Demos\DelphiUnicode\Assorted\Fields\MailMerge2\ shows how to replace a field to RVF content.

icehouse
Posts: 3
Joined: Tue Jan 12, 2010 9:29 pm
Location: Essen

Post by icehouse » Wed Jul 15, 2015 9:16 pm

Thank you for the quick answer.
Yes, I have tested MailMerge2, too but it does not work if TRichViewedit is not placed on a tform. Can you test this?

Post Reply