彩票走势图

富文本编辑器TRichView常用示例二:插入多种文本格式

原创|其它|编辑:郝浩|2013-01-09 10:29:52.000|阅读 1191 次

概述:TRichViewEdit支持以下几种文件格式:图像、RVF、RTF、纯文本(ANSI)。本示例演示如何用OnDropFiles事件插入这几种文件类型。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

TRichViewEdit TRichView 的编辑组件,可编辑图片、表格、Delphi控件和超链接等。默认情况下,TRichViewEdit支持以下几种文件格式:图像、RVF、RTF、纯文本(ANSI)。本示例演示如何用OnDropFiles事件插入这几种文件类型,假设 RVOfficeConverter1:TRVOfficeConverter 放置在表单中:

procedure TForm1.RichViewEdit1DropFiles(Sender: TCustomRichViewEdit;

  Files: TStrings; var FileAction: TRVDropFileAction;

var DoDefault: Boolean);

  {....................................................}

  { This function inserts one file FileName }

  function InsertFile(const FileName: String): Boolean;

  var pic: TPicture;

  gr: TGraphic;

  Ext: String;

  i: Integer;

  begin

    Result := False;

    try

      // 1. Trying to insert as a graphic

      pic := TPicture.Create;

      try

        pic.LoadFromFile(FileName);

        gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));

        gr.Assign(pic.Graphic);

        Sender.InsertPicture('', gr, rvvaBaseline);

        Result := True;

      except;

      end;

      pic.Free;

      if Result then

        exit;

      // 2. Trying to insert as RTF file

      Ext := LowerCase(ExtractFileExt(FileName));

      if Ext='.rtf' then begin

        Sender.InsertRTFFromFileEd(FileName);

        Result := True;

        exit;

      end;

      // 3. Trying to insert as RVF file

      if Ext='.rvf' then begin

        Sender.InsertRVFFromFileEd(FileName);

        Result := True;

        exit;

      end;

      // 4. Trying to insert as text file

      if Ext='.txt' then begin

        Sender.InsertTextFromFile(FileName);

        Result := True;

        exit;

      end;

      // 5. Trying to insert using office converters

      for i := 0 to RVOfficeConverter1.ImportConverters.Count-1 do

        if Pos(Ext, RVOfficeConverter1.ImportConverters[i].Filter)>0 then

          if RVOfficeConverter1.ImportRTF(FileName, i) then begin

            RVOfficeConverter1.Stream.Position := 0;

            Sender.InsertRTFFromFileEd(RVOfficeConverter1.Stream);

            RVOfficeConverter1.Stream.SetSize(0);

            Result := True;

            exit;

          end;

    except

    end;

  end;

  {....................................................}

var i: Integer;

begin

  for i := 0 to Files.Count-1 do

    InsertFile(Files[i]);

  DoDefault := False;

end;

注:OnDropFiles事件在将文件放到编辑器中时触发

type

  TRVDropFilesEvent =

    procedure (Sender: TCustomRichViewEdit;

      Files: TStrings; var FileAction: TRVDropFileAction;

      var DoDefault: Boolean) of object;

  TRVDropFileAction = (rvdfNone, rvdfInsert, rvdfLink);

 property OnDropFiles: TRVDropFilesEvent;

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP