Page 1 of 1

Reload image?

Posted: Sat Jun 27, 2026 5:29 pm
by whisper1980
In FMX with TRichViewEdit on Android and iOS, my images are stored in a database and pulled during the OnImportPicture event (I use what I call linked images... only the URL identifying how to pull the image is saved in the TRichViewEdit's RTF). I allow a user to double click an image and edit it by adding arrows, circles, etc to focus a problem area in the photo. Is there a quick an easy way to refresh the image once I save it back to the database without having to reload the TRichViewEdit? I don't necessarily want to save everything prior to editing the image just to have to reload it to invoke the OnImportPicture event. I thought maybe there might be a better way.

Re: Reload image?

Posted: Wed Jul 01, 2026 12:04 pm
by Sergey Tkachenko
You can find this image in the document and change it.
How is your image identified?
The code below assumes it's identified by item name, so GetItemText is used. It can also be identified by tag (GetItemTag) or property (GetItemExtraStrProperty(rvespImageFileName...)).

Searching for an image having the specified name:

Code: Select all

function FindImage(RVData: TCustomRVData; const Name: String;
  out ImgRVData: TCustomRVData; out ImgItemNo: Integer): Boolean;
var
  i, r, c: Integer;
  Table: TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount - 1 do
    if (RVData.GetItem(i) is TRVGraphicItemInfo) and
      (RVData.GetItemText(i) = Name) then
    begin
      ImgRVData := RVData;
      ImgItemNo := i;
      Result := True;
      exit;
    end
    else if RVData.GetItem(i) is TRVTableItemInfo then
    begin
      Table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to Table.RowCount - 1 do
        for c := 0 to Table.ColCount - 1 do
          if Table.Cells[r, c] <> nil then
          begin
            Result := FindImage(Table.Cells[r, c].GetRVData, Name, ImgRVData, ImgItemNo);
            if Result then
              exit;
          end;
    end;
  Result := False;
end;
Call:

Code: Select all

var
  ImgRVData: TCustomRVData;
  ImgItemNo: Integer;
begin
  if FindImage(MyRichView.RVData, ImageName, ImgRVData, ImgItemNo) then 
  begin
    ImgRVData.SetPictureInfo(ImgItemNo, ...);
    MyRichView.Reformat;
  end;
end;
If you use TRichViewEdit, you can reformat only the paragraph containing the found image. However, if the image is in table cell, this cell's editor must be activated:

Code: Select all

var
  ImgRVData: TCustomRVData;
  ImgItemNo, ItemData: Integer;
  RVE: TCustomRichViewEdit;
begin
  if FindImage(MyRichViewEdit.RVData, ImageName, ImgRVData, ImgItemNo) then 
   begin
     ImgRVData := ImgRVData.Edit;
     RVE := ImgRVData.GetParentControl as TCustomRichViewEdit;
     RVE.BeginItemModify(ImgItemNo, ImgRVData);
     RVE.SetPictureInfo(ImgItemNo, ...);
     RVE.EndItemModify(ImgItemNo, ImgRVData)
   end;
end;