Page 1 of 1

insert text with linefeed (LF / CR)

Posted: Thu Sep 25, 2014 6:30 am
by mverbeek
The problem is simple:
I have a mail merge where I replace a LABEL [SIGNING] with a certain text.
The text contains a linefeed/carriage return: 'Best regards,'#13#10'Marcel'


Here is (a simplified) part of my source.

strSigning := 'Best regards,'#13#10'Marcel'
listSigning := TStringList.Create;
listSigning.Text := strSigning;

if RVData.GetItemTag(i) = 'txt_SIGNING' then
begin
CurLabelItem := TRVLabelItemInfo(RVData.GetItem(i));
CurLabelItem.Text := '';

RVInsertString(RVData, i + 1, 'xxx', CurLabelItem.TextStyleNo, -1);
RVData.SetItemText(i + 1, strSigning);

// TRIED 1: RVInsertString
RVInsertString(RVData, j , strSigning, CurLabelItem.TextStyleNo, -1);
// RESULT text is placed as one string 'Best regards,Marcel'
// ! this is a correct result as mentioned in your documentation

// TRIED 2: RVInsertString for each item in TStringList
AddLines(RVData, listSigning, i);
// RESULT text is placed as one string 'Best regards,Marcel'
// ? can I add a linefeed after the RVInsertString

// TRIED 3: Use AddTextNLW
RVData.AddTextNLW(strSigning, CurLabelItem.TextStyleNo, CurLabelItem.ParaNo -1, CurLabelItem.ParaNo-1, true);
// RESULT takes the linefeed correctly, only places the text at the END of the document (as mentioned in your documentation)
end;

procedure AddLines(RVData: TCustomRVData; listSigning: TStringList; j: integer);
var i: integer;
begin
for i := 0 to strSigning.Count - 1 do
begin
j := j + 1;
RVInsertString(RVData, j , listSigning, CurLabelItem.TextStyleNo, -1);
end;
end;

Here is (a simplified) part of my merge-document.

'
Dear John,

.....
.....

[SIGNING]

SOLIT application development
'


QUESTION
After several hours of investigating your documentation, I still did not find a solution.
Can you assist me on this?



Best regards,
Marcel

Posted: Thu Sep 25, 2014 11:38 am
by Sergey Tkachenko
You pass -1 to ParaNo parameter, so it adds text to the end of the same paragraph. Correction:

Code: Select all

procedure AddLines(RVData: TCustomRVData; listSigning: TStringList; j: integer); 
var i, CurParaNo: integer; 
begin 
  CurParaNo := -1;
  for i := 0 to strSigning.Count - 1 do 
  begin 
    j := j + 1; 
    RVInsertString(RVData, j , listSigning[i], CurLabelItem.TextStyleNo, CurParaNo); 
    CurParaNo := CurLabelItem.ParaNo;
  end; 
end; 
Also, you can take InsertMultilineText function from demos http://www.trichview.com/forums/viewtopic.php?t=8
(choose a demo that supports multiline text in a field value)