insert text with linefeed (LF / CR)

General TRichView support forum. Please post your questions here
Post Reply
mverbeek
Posts: 4
Joined: Fri Jan 17, 2014 11:42 am

insert text with linefeed (LF / CR)

Post 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
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Post Reply