Skip to main content

IdxRichEditDocumentImageCollection.Insert(IdxRichEditDocumentPosition,TGraphic) Method

Inserts a new inline image at the specified position in a subdocument.

Declaration

function Insert(const APos: IdxRichEditDocumentPosition; AImage: TGraphic): IdxRichEditDocumentImage;

Parameters

Name Type Description
APos IdxRichEditDocumentPosition

The target document position.

AImage TGraphic

The source image container.

Returns

Type Description
IdxRichEditDocumentImage

The created inline image.

Remarks

Call the Insert function to add a new inline image at any position in the parent subdocument.

Code Example

The following code example allows users to select an image in any format and insert the image at the current caret position in a document opened in a TdxRichEditControl:

uses
..., dxSVGImage;  // This unit contains the TdxSVGImageCodec class declaration
//...
procedure TMyForm.cxButton1Click(Sender: TObject);
var
  ADocument: IdxRichEditDocument;
  AImageContainer: TdxSmartImage;
  AFileName: string;
begin
  ADocument := dxRichEditControl1.Document;
  OpenPictureDialog1.Execute(Handle);  // Invokes the "Open" dialog to allow a user to select the source image file
  AFileName := OpenPictureDialog1.FileName;
  if (AFileName = '') then Exit;  // Exits the procedure if a user selects no image
  AImageContainer := TdxSmartImage.Create;  // Creates a Smart Image container
  AImageContainer.LoadFromFile(AFileName);
  if (AImageContainer.ImageCodec = TdxSVGImageCodec) then  // If the container has loaded an SVG image
    AImageContainer.ConvertToBitmap;  // Rasterizes the vector image
  ADocument.Images.Insert(ADocument.CaretPosition, AImageContainer);  // Creates a new inline image from the stored bitmap and inserts it at the caret position within the opened document
  AImageContainer.Free;  // Destroys the Smart Image container to prevent memory leaks
end;

VCL Rich Edit: An Inline Image Example

Limitations

An inline document image’s Office Image container does not support vector images to ensure compatibility with popular document formats. Ensure that the source image container (a TdxSmartImage or TdxSmartGlyph instance) does not contain an SVG image. Otherwise, an exception occurs.

Tip

You can call the image container’s ConvertToBitmap procedure to rasterize the stored image as demonstrated in the code example in the current help topic.

See Also