Page 1 of 1

AddPictureEx at the right position - not to the end

Posted: Fri Mar 15, 2013 12:33 pm
by AXSchmidt
Im searching a text (aText) in a RVReportHelper.RichView.RVData (aRVData) and try to replace it with an image (from aFileName). But my procedure puts the image to the end of the document... what can i use to insert the pic at the right position?

Code: Select all

procedure RVImportPic(aRVData: TCustomRVData; aFileName, aText: string);
  for i := 0 to aRVData.ItemCount-1 do
    if aRVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(aRVData.GetItem(i));
      for r := 0 to table.Rows.Count-2 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c] <> nil then
            RVImportPic(table.Cells[r,c].GetRVData, aFileName, aText);
    end
    else if aRVData.GetItemStyle(i) >= 0 then
      if Pos(aText, aRVData.GetItemText(i)) > 0 then begin
        newtext := StringReplace(aRVData.GetItemText(i), aText, '', [rfReplaceAll, rfIgnoreCase]);
        if newtext = '' then
          aRVData.DeleteItems(i, 1)
        else
          aRVData.SetItemText(i, newtext);
        aPic:= TPicture.Create;
        if FileExists(aFileName) then
        begin
          aPic.LoadFromFile(aFileName);
          aRVData.AddPictureEx(aText, aPic.Graphic, -1, rvvaBaseline);
        end;
      end;

Posted: Fri Mar 15, 2013 12:45 pm
by AXSchmidt
and is it posible to take over the align (=center) from aText?

Posted: Fri Mar 15, 2013 12:47 pm
by Sergey Tkachenko
TRichView supports two basic operations: adding to the end, and (in editor) inserting in the position of the caret.
The only documented method for insertion is InsertRVFFromStream.
Insertion in the middle and deletion must be done accurately, because it's very simple to create invalid documents.
I suggest using the demo mailmerge-text4.zip from http://www.trichview.com/forums/viewtopic.php?t=8 as a base.