TRichView中文文档
TRichView 是Delphi/C++Builder 控件,主要用于显示、编辑和打印超文本文档。
新版本解决多个兼容性问题,更新了字符串标签、剪贴板、RTF和DB组件。
附:TRichView v14版下载
兼容性问题
Item tags是字符串,不再是整数型
OnRVFPictureNeeded参数改变
TRichView.LoadText, LoadTextFromStream, SaveText, SaveTextToStream, TRichViewEdit.InsertTextFromFile 有了新的参数。
TRVLongOperation的声明类型已经改变
以下全局变量从RVTable.pas中移除:RichViewTableGridStyle, RichViewTableGridStyle2, RichViewTableGridColor,被替换为TRVStyle属性。
风格模板
默认情况下,风格模板不能被使用,需激活风格模板,设置TRichView.UseStyleTemplates = True。
在TRichViewEdit中,你可以应用指定的模板样式到选定区域,使用这些方法:ApplyStyleTemplate, ApplyTextStyleTemplate, ApplyParaStyleTemplate. 样式模板可用ChangeStyleTemplates方法编辑。
RTF
TRichView.RTFOptions中的新选项:rvrtfSavePngAsPng。如果默认有这个选项,PNG图像也会被保存为PNG格式。
打印
表格行的新属性: KeepTogether;
新的表格方法: SetRowPageBreakBefore, SetRowKeepTogether;
table.PrintOptions新选项: rvtoContinue;
新属性:TCustomRVPrint.IgnorePageBreaks。
旋转
表格单元格可旋转 90°, 180°或 270。
一个新的方法返回项坐标: GetItemCoordsEx; 它考虑到了单元格的旋转。
字符串标签
新属性:cell tags;
从13.2版本开始,项目标签是字符串(Unicode for Delphi 2009或更高,ANSI老版本的Delphi),从整数到PChar无需类型转换!
64-bit
32-bit 和 64-bit编译器均支持RAD Studio XE2+。
注意: TRVOfficeConverter 可以编译为64-bit应用程序,但列表的转换器将为空 (因为转换器是32-bit DLLs,不能再64-bit应用中使用)。
HTML存储
TRichView.SaveHTMLEx可保存扩展的背景图像;
TRichView.SaveHTMLEx 能更好的保存列表标记 (无论是在常规或rvsoMarkersAsText 模式);
TRichView.OnSaveImage2事件新增"hidden"参数。
DB组件
如果rvfoLoadBack在 RVFOptions中, TDBRichView会在加载数据前清空 BackgroundBitmap;
如果rvfoLoadBack在RVFOptions 和 FieldFormat=rvdbRVF中, TDBRichViewEdit会在加载数据前清空 BackgroundBitmap。
剪贴板
TRichViewEdit 可以粘贴URL,新增方法:PasteURL;
新属性:AcceptPasteFormats允许限制格式列表;
新属性:DefaultPictureVAlign定义一个对齐以粘贴和放置图像。
RichEdit的实现MSNQQ 中的动画表情
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: $; D2: $; D3: $; D4: ($C0, $, $, $, $, $, $,
$));
EM_GETOLEINTERFACE = WM_USER + ;
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(, 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, , FStorage) <> S_OK then
begin
Showmessage('Error to create storage');
exit;
end;
//取得RichEdit的接口
Sendmessage(Editor.handle,EM_GETOLEINTERFACE,,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), );
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 := ;
//the very object
reobject.poleobj := m_lpObject;
//client site contain the object
reobject.polesite := FClientSite;
//the storage
reobject.pstg := FStorage;
sizel.cx := ;
sizel.cy := ;
reobject.sizel := sizel;
//Sel all text
SendMessage(Editor.Handle, EM_SETSEL, , -);
SendMessage(Editor.Handle, EM_GETSEL, dwStart, dwEnd);
SendMessage(Editor.Handle, EM_SETSEL, dwEnd + , dwEnd + );
//Insert after the line of text
FRTF.InsertObject(reobject);
SendMessage(Editor.Handle, EM_SCROLLCARET, , );
//VARIANT_BOOL ret;
//do frame changing
m_lpAnimator.TriggerFrameChange();
//show it
m_lpObject.DoVerb(OLEIVERB_UIACTIVATE, Nil, FClientSite, , Editor.Handle,Rect);
// m_lpObject.DoVerb(
m_lpObject.DoVerb(OLEIVERB_SHOW, Nil, FClientSite, , Editor.Handle, Rect);
//redraw the window to show animation
redrawwindow(Handle, nil, , RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ERASENOW orRDW_ALLCHILDREN);
finally
FRTF:=nil;
FClientSite := nil;
FStorage :=nil;
end;
end;
end.
SetTargetToSelection
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 < 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;
手机扫一扫
移动阅读更方便
你可能感兴趣的文章