if a user writes ":(" then smile.bmp replace there but when smile.bmp created in rxrichbox cursor had first position i want when user writes":(" then replace there smile.bmp unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, RxRichEd; type TForm1 = class(TForm) Button1: TButton; re: TRxRichEdit; Image1: TImage; Memo1: TMemo; Edit1: TEdit; procedure reKeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } ax:string; x:integer; end; var Form1: TForm1; implementation {$R *.dfm} function BitmapToRTF(pict: TBitmap): string; var bi,bb,rtf: string; bis,bbs: Cardinal; achar: ShortString; hexpict: string; I: Integer; begin GetDIBSizes(pict.Handle,bis,bbs); SetLength(bi,bis); SetLength(bb,bbs); GetDIB(pict.Handle,pict.Palette,PChar(bi)^,PChar(bb)^); rtf := '{\rtf1 {\pict\dibitmap '; SetLength(hexpict,(Length(bb) + Length(bi)) * 2); I := 2; for bis := 1 to Length(bi) do begin achar := Format('%x',[Integer(bi[bis])]); if Length(achar) = 1 then achar := '0' + achar; hexpict[I-1] := achar[1]; hexpict[I] := achar[2]; Inc(I,2); end; for bbs := 1 to Length(bb) do begin achar := Format('%x',[Integer(bb[bbs])]); if Length(achar) = 1 then achar := '0' + achar; hexpict[I-1] := achar[1]; hexpict[I] := achar[2]; Inc(I,2); end; rtf := rtf + hexpict + ' }}'; Result := rtf; end; procedure TForm1.reKeyPress(Sender: TObject; var Key: Char); var ss:TStringStream; aci:string; v:integer; begin if key=':' then begin ax:=key; end else if ax<>'' then begin if key='(' then begin SS := TStringStream.Create(BitmapToRTF(image1.Picture.Bitmap)); RE.PlainText := False; RE.StreamMode := [smSelection]; RE.Lines.LoadFromStream(SS); SS.Free; ax:=''; end; end; end; end.