怎么在delphi显示html,在Delphi中,如何将简单的字节转换成HTML标记?_delphi_开发99编程知识库...

嘗試了許多沒有給出準確結果的不同解決方案后,我受到了這裡解決方案的啟發: 將RTF轉換為HTML格式,HTML轉換為RTF格式。

它的思想是,TWebBrowser 控制項( 在設計/編輯模式中) 在從剪貼板粘貼時可以處理和轉換正確的文本格式。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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值