TRichView中文文档
TRichView 是Delphi/C++Builder 控件,主要用于显示、编辑和打印超文本文档。
新版本解决多个兼容性问题,更新了字符串标签、剪贴板、RTF和DB组件。
TRichView.LoadText, LoadTextFromStream, SaveText, SaveTextToStream, TRichViewEdit.InsertTextFromFile 有了新的参数。
以下全局变量从RVTable.pas中移除:RichViewTableGridStyle, RichViewTableGridStyle2, RichViewTableGridColor,被替换为TRVStyle属性。
默认情况下,风格模板不能被使用,需激活风格模板,设置TRichView.UseStyleTemplates = True。
在TRichViewEdit中,你可以应用指定的模板样式到选定区域,使用这些方法:ApplyStyleTemplate, ApplyTextStyleTemplate, ApplyParaStyleTemplate. 样式模板可用ChangeStyleTemplates方法编辑。
TRichView.RTFOptions中的新选项:rvrtfSavePngAsPng。如果默认有这个选项,PNG图像也会被保存为PNG格式。
新的表格方法: SetRowPageBreakBefore, SetRowKeepTogether;
table.PrintOptions新选项: rvtoContinue;
新属性:TCustomRVPrint.IgnorePageBreaks。
一个新的方法返回项坐标: GetItemCoordsEx; 它考虑到了单元格的旋转。
从13.2版本开始,项目标签是字符串(Unicode for Delphi 2009或更高,ANSI老版本的Delphi),从整数到PChar无需类型转换!
32-bit 和 64-bit编译器均支持RAD Studio XE2+。
注意: TRVOfficeConverter 可以编译为64-bit应用程序,但列表的转换器将为空 (因为转换器是32-bit DLLs,不能再64-bit应用中使用)。
TRichView.SaveHTMLEx可保存扩展的背景图像;
TRichView.SaveHTMLEx 能更好的保存列表标记 (无论是在常规或rvsoMarkersAsText 模式);
TRichView.OnSaveImage2事件新增"hidden"参数。
如果rvfoLoadBack在 RVFOptions中, TDBRichView会在加载数据前清空 BackgroundBitmap;
如果rvfoLoadBack在RVFOptions 和 FieldFormat=rvdbRVF中, TDBRichViewEdit会在加载数据前清空 BackgroundBitmap。
TRichViewEdit 可以粘贴URL,新增方法:PasteURL;
新属性:AcceptPasteFormats允许限制格式列表;
新属性:DefaultPictureVAlign定义一个对齐以粘贴和放置图像。
RichEdit的实现MSNQQ 中的动画表情
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ActiveX, ComCtrls, RxRichEd, ImageOleLib_TLB; //RxRichEd单元是Rxlib下的RxRichEdit,一套增强功能的RichEdit //ImageOleLib_TLB是从qq的ImageOle.dll引入的类型库 const IID_IOleObject: TGUID = ( D1: $00000112; D2: $0000; D3: $0000; D4: ($C0, $00, $00, $00, $00, $00, $00, $46)); EM_GETOLEINTERFACE = WM_USER + 60; type TForm1 = class(TForm) Button1: TButton; Editor: TRxRichEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var FRTF: IRichEditOle; FLockBytes: ILockBytes; FStorage: ISTORAGE; FClientSite: IOLECLIENTSITE; m_lpObject: IOleObject; m_lpAnimator: TGifAnimator; i_GifAnimator: IGifAnimator; reobject: TReObject; clsid: TGuid; sizel: tagSize; dwStart, dwEnd: DWORD; Rect:TRect; begin try if CreateILockBytesOnHGlobal(0, True, FLockBytes) <> S_OK then begin showmessage('Error to create Global Heap'); exit; end; //建立一个混合文档存取对象 if StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE or STGM_CREATE or STGM_READWRITE, 0, FStorage) <> S_OK then begin Showmessage('Error to create storage'); exit; end; //取得RichEdit的接口 Sendmessage(Editor.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF)); if FRTF.GetClientSite(FClientSite)<>S_OK then begin ShowMessage('Error to get ClentSite'); Exit; end; CoInitializeEx(nil, COINIT_APARTMENTTHREADED); m_lpAnimator := TGifAnimator.Create(Self); i_GifAnimator := m_lpAnimator.ControlInterface; i_GifAnimator.LoadFromFile('c:\ti.gif'); i_GifAnimator.QueryInterface(IID_IOleObject, m_lpObject); OleSetContainedObject(m_lpObject, True); FillChar(ReObject, SizeOf(ReObject), 0); ReObject.cbStruct := SizeOf(ReObject); m_lpObject.GetUserClassID(clsid); ReObject.clsid := clsid; reobject.cp := REO_CP_SELECTION; //content, but not static reobject.dvaspect := DVASPECT_CONTENT; //goes in the same line of text line reobject.dwFlags := REO_BELOWBASELINE; //REO_RESIZABLE | reobject.dwUser := 0; //the very object reobject.poleobj := m_lpObject; //client site contain the object reobject.polesite := FClientSite; //the storage reobject.pstg := FStorage; sizel.cx := 0; sizel.cy := 0; reobject.sizel := sizel; //Sel all text SendMessage(Editor.Handle, EM_SETSEL, 0, -1); SendMessage(Editor.Handle, EM_GETSEL, dwStart, dwEnd); SendMessage(Editor.Handle, EM_SETSEL, dwEnd + 1, dwEnd + 1); //Insert after the line of text FRTF.InsertObject(reobject); SendMessage(Editor.Handle, EM_SCROLLCARET, 0, 0); //VARIANT_BOOL ret; //do frame changing m_lpAnimator.TriggerFrameChange(); //show it m_lpObject.DoVerb(OLEIVERB_UIACTIVATE, Nil, FClientSite, 0, Editor.Handle,Rect); // m_lpObject.DoVerb( m_lpObject.DoVerb(OLEIVERB_SHOW, Nil, FClientSite, 0, Editor.Handle, Rect); //redraw the window to show animation redrawwindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ERASENOW orRDW_ALLCHILDREN); finally FRTF:=nil; FClientSite := nil; FStorage :=nil; end; end; end.
SetTargetToSelection
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
procedure TChildFrm.SetTargetToSelection(const Target: String); var i, StartNo, EndNo, StartOffs, EndOffs: Integer; rveC: TCustomRichViewEdit; begin { Important: when working with the selection item indices, always use TopLevelEditor. } rveC := rve.TopLevelEditor; { Receiving the range of selected items } rveC.GetSelectionBounds(StartNo, StartOffs, EndNo, EndOffs, True); { If nothing is selected, exiting } if StartNo < 0 then exit; { May be the outermost items are not included in the selection? In this case, excluding them } if StartOffs >= rveC.GetOffsAfterItem(StartNo) then inc(StartNo); if EndOffs <= rveC.GetOffsBeforeItem(EndNo) then dec(EndNo); { Changing tags of the selected items } rveC.BeginUndoGroup(rvutTag); rveC.SetUndoGroupMode(True); if Target <> '' then for i := StartNo to EndNo do rveC.SetItemTagEd(i, Target) else for i := StartNo to EndNo do rveC.SetItemTagEd(i, ''); rveC.SetUndoGroupMode(false); end;
解决RichViewEdit乱码问题
⑴ 设置RichViewEdit下面的几个属性:
① RTFReaderProperties → ParaStyleMode → rvrsAddIfNeeded
② RTFReaderProperties → TextStyleMode → rvrsAddIfNeeded
③ RTFReaderProperties → UnicodeMode → rvruOnlyUnicode
⑵ 设置RVStyle:
双击该控件,在弹出的窗体里选定里面5个子项,然后在属性窗体里找到
Unicode属性,全部改为:True;