Table of Contents

Images and links

Inserting images

// Insert an image from a file at the cursor position
RichEditor1.InsertImageFromFile('photo.png');

// Insert from a bitmap
var bmp: TBitmap;
begin
  bmp := TBitmap.Create;
  try
    bmp.LoadFromFile('photo.png');
    RichEditor1.InsertImage(bmp);
  finally
    bmp.Free;
  end;
end;

Graphic selection handles

When a user clicks an embedded image, selection handles appear around it. The handle appearance is controlled by GraphicSelection:

Property Description
GraphicSelection.Color Background color of the selection grip squares
GraphicSelection.BorderColor Border color of the grip squares
GraphicSelection.Style gsRectangle for square handles, gsCircle for round handles
RichEditor1.GraphicSelection.Style := gsCircle;
RichEditor1.GraphicSelection.Color := gcDodgerBlue;
RichEditor1.GraphicSelection.BorderColor := gcWhite;
// Insert a clickable link at the cursor position
RichEditor1.InsertURL('https://www.tmssoftware.com', 'TMS Software');

Auto-open URLs

When AutoOpenURL is True, clicking a link in the editor opens it in the default browser:

RichEditor1.AutoOpenURL := True;

To handle link clicks yourself, assign OnAnchorClick:

procedure TForm1.RichEditor1AnchorClick(Sender: TObject; const AURL: String);
begin
  // Custom handling instead of auto-open
  ShowMessage('Link clicked: ' + AURL);
end;
RichEditor1.InsertText('See the product page: ');
RichEditor1.InsertURL('https://www.tmssoftware.com', 'TMS Software');
RichEditor1.InsertLineBreak;
RichEditor1.InsertLineBreak;
RichEditor1.InsertImageFromFile('banner.png');
  • TTMSFNCRichEditorInsertImageFromFile, InsertImage, InsertURL, AutoOpenURL, GraphicSelection, OnAnchorClick

See also