delphi RTF 转换 HTML and HTML 转换 RTF.  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi RTF 转换 HTML and HTML 转换 RTF.


uses SHDocVw, MSHTML;


function ClipboardToHTML(AParent: TWinControl): WideString;

var

  wb: TWebBrowser;

  function WaitDocumentReady: Boolean;

  var

    StartTime: DWORD;

  begin

    StartTime := GetTickCount;

    while wb.ReadyState <> READYSTATE_COMPLETE do

    begin

      Application.HandleMessage;

      if GetTickCount >= StartTime + 2000 then // time-out of max 2 sec

      begin

        Result := False; // time-out

        Exit;

      end;

    end;

    Result := True;

  end;

begin

  Result := '';

  wb := TWebBrowser.Create(nil);

  try

    wb.Silent := True;

    wb.Width := 0;

    wb.Height := 0;

    wb.Visible := False;

    TWinControl(wb).Parent := AParent;

    wb.HandleNeeded;

    if wb.HandleAllocated then

    begin

      wb.Navigate('about:blank');

      (wb.Document as IHTMLDocument2).designMode := 'on';

      if WaitDocumentReady then

      begin

        (wb.Document as IHTMLDocument2).execCommand('Paste', False, 0);

        Result := (wb.Document as IHTMLDocument2).body.innerHTML;

      end;

    end;

  finally

    wb.Free;

  end;

end;


procedure TForm1.Button1Click(Sender: TObject);

begin

  RichEdit1.SelectAll;

  RichEdit1.CopyToClipboard;


  ShowMessage(ClipboardToHTML(Self));

end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.039883852005005 seconds