TCustomRichView.AddPicture

<< Click to display table of contents >>

TCustomRichView.AddPicture

Adds a picture to the end of document

procedure AddPicture(const Name: TRVUnicodeString; gr: TRVGraphic;
  ParaNo: Integer = -1; VAlign: TRVVAlign = rvvaBaseline; 

  const Tag: TRVTag = RVEMPTYTAG; ImageWidth: TRVStyleLength = 0;

 ImageHeight: TRVStyleLength = 0);

(changed in versions 18 and 21)

Parameters:

Name name of this picture item, any string. Name must not contain CR and LF characters. TRichView does not use item names itself, they are for your own use.

gr picture to insert. By default, this picture will be owned by TRichView control, and you must not free it. However, you can specify nonzero rvepShared extra item property, and this graphic object will be shared (you need to free it yourself after TRichView is cleared).

Rarely used images may be "deactivated", i.e. stored in a memory stream and destroyed (see RichViewMaxPictureCount). Shared images are never deactivated.

VAlign vertical align of this picture, relative to its line, see TRVVAlign for possible values.

If ParaNo=-1, the method adds an item to the end of the last paragraph. If ParaNo>=0, this item starts a new paragraph using attributes defined in Style.ParaStyles[ParaNo].

Tag tag of this picture item.

The image is displayed stretched to ImageWidth x ImageHeight (if they are non-zero, see rvepImageWidth and rvepImageHeight in IDH_Type_TRVExtraItemProperty).

Alternatives:

If you want to add a picture-hyperlink, add a hot picture instead.

If you want to add a hyperlink-picture from image list, add a hotspot instead.

If you want to add a simple (not a hyperlink) picture from image list, add a bullet instead.

Methods type: viewerstyle viewer-style.

Example 1:

procedure AddBitmapFromFile(rv: TCustomRichView; 

  const FileName: String; ParaNo: Integer);

var bmp: TBitmap;

begin

  bmp := TBitmap.Create;

  bmp.LoadFromFile(FileName);

  rv.AddPicture('', bmp, ParaNo);

end;

...

// creating document with 2 pictures

// in the same paragraph

rv.Clear;

AddBitmapFromFile(rv, 'd:\pic1.bmp'0);

AddBitmapFromFile(rv, 'd:\pic2.bmp', -1);

rv.Format;

Example 2: adding shared images

procedure AddBitmapFromFile(rv: TCustomRichView; 

  const FileName: String; ParaNo: Integer);

 

bmp := TBitmap.Create;

bmp.LoadFromFile('c:\pic.bmp');

rv.AddPicture('', bmp, 0);

rv.SetItemExtraIntProperty(rv.ItemCount-1, rvepShared, 1);

rv.AddPicture('', bmp, -1);

rv.SetItemExtraIntProperty(rv.ItemCount-1, rvepShared, 1);

rv.Format;

// you must free bmp yourself when rv is cleared.

See also methods:

Format;

FormatTail;

SetAddParagraphMode.

See also methods of TRichViewEdit:

InsertPicture.

See also properties of TRVStyle:

ParaStyles.

See also:

Item types;

Other methods for appending items;

"Tags".

Related deprecated methods:

procedure AddPictureExTag(const Name: TRVUnicodeString; gr: TGraphic;

  ParaNo: Integer; VAlign: TRVVAlignconst Tag: TRVTag);

procedure AddPictureEx(const Name: TRVUnicodeString; gr: TGraphic;

  ParaNo: Integer; VAlign: TRVVAlign);

These methods provide subset of functionality of AddPicture.