原創|其它|編輯:郝浩|2013-01-09 10:29:52.000|閱讀 1260 次
概述: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@fc6vip.cn
文章轉載自:慧都控件