Next Line Problem

General TRichView support forum. Please post your questions here
Post Reply
Crowbar
Posts: 82
Joined: Wed Oct 11, 2006 8:54 pm
Location: Germany

Next Line Problem

Post by Crowbar »

Hi,
i has a string with following content:
" 'Hello world1'#$D#$A'Hello world2' "
The "#$D#$A" - code is for write "Hello world2" on the next line.
Examble:
Hello world1
Hello world2

But in the TRichViewEdit, it is shown so (in a line):
Hello world1 Hello world2

I work with "RVData.SetItemTextA(i,s).
I must replace different strings.

Examble:
Marker {test} replace with string " 'Hello world1'#$D#$A'Hello world2' ".

Result in RichViewEdit should be:
Hello world1
Hello world2

Who can help me?

Best regards
Crowbar
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

SetItemTextA changes text of one item.
Item text cannot contain line break characters, this string is not valid for SetItemTextA.

Please describe me what do you want to implement, I'll try to help you.
Crowbar
Posts: 82
Joined: Wed Oct 11, 2006 8:54 pm
Location: Germany

Post by Crowbar »

Hello,
I have in my RichViewEdit of deceased macroses. These macroses are replaced automatically with a text.
This text can also have break characters.

Examble, in the RichViewEdit is a macro:
<remind>

This macros seeks and replaces it with a text:
$text:='Thank you for your order!'+#13#10+'With this goods delivery, your order is closed.'

The "#13#10" characters is for the next line.
It works fine if no break characters are in it.

I must "search and replace" uses and not the code of the "mailmerge-freestyle" - Demo (-> not valid for SetItemTextA)!?
Crowbar
Posts: 82
Joined: Wed Oct 11, 2006 8:54 pm
Location: Germany

Post by Crowbar »

Hello,
I found a solution:

Code: Select all

...
with RichViewEdit do
  begin
      Clear;
      LoadRTF('temp.rtf');
      Format;
      SetFocus;
      while SearchText('<remind>',[rvseoDown]) do
        begin
           InsertText('Thank you for your order!'+#13#10+'With this goods delivery, your order is closed.',false);
        end;
  end;
...
It works fine, but is it so right? I think ... :roll:

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

Post by Sergey Tkachenko »

It's not so simple, if this is not an editing operation (for implementation of editing operation that can be undone and redone, select the old text then call InsertText).

Item cannot contain multiline text, each line must be in its own items.
TRichView does not have documented methods for inserting items at the specified position (other than InsertRVFFromStream), so you need to use undocumented methods.

I created a new mail merging demo, http://www.trichview.com/support/files/ ... -text3.zip
Field codes are text in {}, for example {NAME}, field values are multiline text.
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, your code is correct, but
1) InsertText is an editing operation, it can be undone by user (Ctrl+Z)
2) It is relatively slow.

The demo I posted is much more complicated, but it is fast and it works not only in editor but also in TRichView.
You can copy the key methods (InsertMultilineText, FillFields) in your application without changes.

Note: you cannot mix editing operations and non-editing operations.
If you will call FillFields for TRichViewEdit, do it just after the document is loaded (before calling Format). Or call RichViewEdit1.ClearUndo.
Crowbar
Posts: 82
Joined: Wed Oct 11, 2006 8:54 pm
Location: Germany

Post by Crowbar »

Ok, thanks for your help!
One question to mailmerge-text3 demo.
I would like to output my result in a TRichViewEdit with rtf format (I load a rtf file with my macros.)
How I must change the code:

Code: Select all

...
Index := 0; 
ItemCount := 0;
rvOutput.Clear;
while Index<Persons.Count do begin
 Stream := TMemoryStream.Create;
 rve.SaveRVFToStream(Stream, False);
 Stream.Position := 0;
 rvOutput.InsertRVFFromStream(Stream, ItemCount);
 Stream.Free;
  if rvOutput.ItemCount>ItemCount then begin
   // starting from new page
  if ItemCount>0 then
   rvOutput.PageBreaksBeforeItems[ItemCount] := True;
  // replacing field codes
   FillFields(rvOutput.RVData, ItemCount);
  end;
  ItemCount := rvOutput.ItemCount;
  inc(Index);
 end;
 rvOutput.Format;
...
Crowbar
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

First, this demo generates output document repeating the template several times, one time for each record (each person in this demo).
If you need to generate document only for one record, the code should be changed to:

Code: Select all

 Stream := TMemoryStream.Create; 
 rve.SaveRVFToStream(Stream, False); 
 Stream.Position := 0; 
 rvOutput.Clear;
 rvOutput.LoadRVFFromStream(Stream); 
 Stream.Free; 
 FillFields(rvOutput.RVData, 0); 
 rvOutput.Format; 
If the document is stored in template.rtf, use this code:

Code: Select all

  rvOutput.Clear;
 rvOutput.Clear;
 rvOutput.DeleteUnusedStyles(True, True, True);
 rvOutput.LoadRTF('template.rtf'); 
 FillFields(rvOutput.RVData, 0); 
 rvOutput.Format; 
If you need to generate a document like in this demo (repeating the template), it's also not difficult with RTF...
Crowbar
Posts: 82
Joined: Wed Oct 11, 2006 8:54 pm
Location: Germany

Post by Crowbar »

Thank you, for your help! :)

Crowbar
Post Reply