Page 1 of 1

TReportRichview and Insert* methods

Posted: Wed Sep 10, 2014 12:19 pm
by apprise
We use ricvhiew to define letter templates and then generate personalized letters. Everything worked excellently until we refactored our application to multitier using datasnap technology.
Then we started getting a lot of 'Canvas' errors on server side. Searching about that topic I found that TRichviewEdit is not threadsafe and that I should use TReportRichView instead.

The main problem here is that TReportRichView is missing some important methods like:
* InsertText
* InsertItem to insert tables
* InsertRVFFromStreamEd
* InsertPageBreak
and some less important methods like:
* ApplyTextStyle (set font style to barcode)
* ApplyStyleConversion (bold, italic, underline)
* ApplyParaStyleConversion (aligment)

Is there any chance that these method will get introduced to TReportRichView?

I also included code snippet of current usage.

Code: Select all

procedure ScanData(ARVData: TCustomRVFormattedData);
var
  content, replacement: string;
  replace: Boolean;
  startItemNo, startItemOffs, endItemNo, EndItemOffs: Integer;
  lStartItemNo, lStartItemOffs, lEndItemNo, lEndItemOffs: Integer;
  offs: Integer;
  rvData: TCustomRVFormattedData;
begin
  rvData := TCustomRVFormattedData(ARVData.Edit);
  offs := rvData.GetOffsBeforeItem(0);
  rvData.SetSelectionBounds(0, offs, 0, offs); // Move to beginning
  while rvData.SearchTextR(True, False, False, False, True, False, False, RVU_GetRawUnicode(StartTag)) do
  begin
    rvData.GetSelectionBounds(startItemNo, startItemOffs, endItemNo, EndItemOffs, True);
    if not rvData.SearchTextR(True, False, False, False, True, True, False, RVU_GetRawUnicode(EndTag)) then
      raise EUnclosedFieldException.Create(_('Unclosed field: %s', [StartTag]));
    rvData.GetSelectionBounds(lStartItemNo, lStartItemOffs, lEndItemNo, lEndItemOffs, True);

    // Select tag content
    rvData.SetSelectionBounds(startItemNo, startItemOffs, lEndItemNo, lEndItemOffs);
    content := Trim(RVU_RawUnicodeToWideString(rvData.GetSelTextR(True)));
    content := Copy(content, Length(StartTag) + 1, Length(content) - Length(StartTag) - Length(EndTag));
    if content = '' then
      Continue;

    replace := True;
    replacement := '';
    OnData(FOrigTemplate, StartTag, EndTag, content, replacement, replace);
    if replace then
    begin
      FOrigTemplate.InsertText(replacement, True);
      rvData.Format(True, False);
    end;
  end;
end;
Currently we have partially working solution to make invisible Richview with allocated hwnd, what works most of the time, but not always

Code: Select all

FHwnd := AllocateHWnd(nil);
FRichView := TRVTemplateEdit.CreateParented(FHwnd);
FRichView.Visible := False; 
FRichView.Options := FRichView.Options - [rvoFormatInvalidate];

Posted: Wed Sep 10, 2014 1:51 pm
by Sergey Tkachenko
These methods are editing methods, they will never be added to non-editing TRichView.
Also, they are not efficient for replacing fields with values - too slow.
I suggest to use one of examples from http://www.trichview.com/forums/viewtopic.php?t=8
instead of SearchText and InsertText.
They do not require editing abilities, and they are much faster.

Please do not call Format method for ppRichView.RichView, it is useless and may even crash (if a document contains tables)

Posted: Thu Sep 11, 2014 7:24 am
by apprise
These mail merge examples are very simplified.
In our system all tags are at least 2 chars and there are two kind of tags:
1) simple tags {{tag}}
2) html like tags {tag} content {/tag}
and replaced values may contain new tags.

With the first case mailmerge4 example works with modifications, but there are problems with the latter one, because starttag and endtag may exist in different items.

Posted: Thu Sep 11, 2014 11:52 am
by Sergey Tkachenko
I can suggest to improve one of this demos yourself.
They contain the main thing: how to insert data at the specified position, all other functionality depend on the application logic.

One more topic to look at: http://www.trichview.com/forums/viewtopic.php?t=9