Next Line Problem
Next Line Problem
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
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
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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)!?
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)!?
Hello,
I found a solution:
It works fine, but is it so right? I think ...
Regards
Crowbar
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;
...
Regards
Crowbar
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
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:
Crowbar
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;
...
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
If the document is stored in template.rtf, use this code:
If you need to generate a document like in this demo (repeating the template), it's also not difficult with RTF...
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;
Code: Select all
rvOutput.Clear;
rvOutput.Clear;
rvOutput.DeleteUnusedStyles(True, True, True);
rvOutput.LoadRTF('template.rtf');
FillFields(rvOutput.RVData, 0);
rvOutput.Format;