[Demos] Mail Merge

Demos, code samples. Only questions related to the existing topics are allowed here.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re:

Post by Ceprotec »

Sergey Tkachenko wrote: Tue May 05, 2009 1:37 pm MainMerge-Text4
mailmerge-text4.zip

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

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

[+] History of updates
2015-Mar-26: RVF field type is added
2018-Apr-30: compatibility with TRichView 17.3. Unicode text in all versions of Delphi. Tab characters are allowed in text field values.
[+] Old versions
https://www.trichview.com/support/files ... -text4.zip - for TRichView 17.2 and older
How to insert the RVF in the same line as the field?
Image
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Re:

Post by Sergey Tkachenko »

Ceprotec wrote: Wed Nov 15, 2023 12:52 am How to insert the RVF in the same line as the field
See MailMerge-Text4 demo: https://www.trichview.com/forums/viewto ... 707#p12707
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Re:

Post by Ceprotec »

Sergey Tkachenko wrote: Wed Nov 15, 2023 7:17 am
Ceprotec wrote: Wed Nov 15, 2023 12:52 am How to insert the RVF in the same line as the field
See MailMerge-Text4 demo: https://www.trichview.com/forums/viewto ... 707#p12707
This is the MailMerge-Text4 demo.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demos] Mail Merge

Post by Sergey Tkachenko »

Oh, sorry.
But I do not understand the question.
In this demo, the field content (RVF or text) is inserted in the line that contains field code.

You edited the template so that it contains a single line, so RVF field is inserted in this line.

(this demo repeats the result for each line in Persons.txt)
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: [Demos] Mail Merge

Post by Ceprotec »

I would like to insert the RVF at the end of the template line and not on a new line...

Image

I can adapt this function to only remove the last blank line.
Sergey Tkachenko wrote: Wed Nov 02, 2005 9:19 pm Modification of DeleteBlankLines - removing blank lines only from the end of the document:

Code: Select all

procedure DeleteTrailingBlankLines(RVData: TCustomRVData); 
var i: Integer; 
begin 
  for i := RVData.ItemCount-1 downto 1 do 
    if RVData.IsParaStart(i) and (RVData.GetItemStyle(i)>=0) and 
      (RVData.GetItemText(i)='') then 
      RVData.DeleteItems(i,1)  
    else
      break;
end;
Call:

Code: Select all

DeleteBlankLines(RichViewEdit1.RVData); 
RichViewEdit1.ClearUndo; 
RichViewEdit1.Format;
I don't think it's very elegant, is there any other way to do this?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demos] Mail Merge

Post by Sergey Tkachenko »

So, you want to add the first paragraph of each record to the last paragraph of the previous record?

Change TForm1.Button1Click. The key method is AppendRVFFromStream(..., -1).

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var Stream: TStream;
    ItemCount: Integer;
begin
  Index := 0; // index of the current person
  ItemCount := 0;
  rvOutput.Clear;
  while Index<Persons.Count do
  begin
    // copying rve to the end of rvOutput
    Stream := TMemoryStream.Create;
    rve.SaveRVFToStream(Stream, False);
    Stream.Position := 0;
    if Index = 0 then
      rvOutput.InsertRVFFromStream(Stream, ItemCount)
    else
      rvOutput.AppendRVFFromStream(Stream, -1);
    Stream.Free;
    // processing the last added copy of template
    if rvOutput.ItemCount>ItemCount then
    begin
      // replacing field codes
      FillFields(rvOutput.RVData, ItemCount);
    end;
    ItemCount := rvOutput.ItemCount;
    inc(Index);
  end;
  rvOutput.Format;
end;
Post Reply