AddPictureEx at the right position - not to the end

General TRichView support forum. Please post your questions here
Post Reply
AXSchmidt
Posts: 20
Joined: Thu Mar 15, 2012 3:16 pm

AddPictureEx at the right position - not to the end

Post 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;
AXSchmidt
Posts: 20
Joined: Thu Mar 15, 2012 3:16 pm

Post by AXSchmidt »

and is it posible to take over the align (=center) from aText?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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