这里我们介绍一些关于在一个Pascal程序窗体中显示或者通过调用浏览器来显示网页的组件。
通过浏览器打开一个页面显示
OpenURL
OpenURL是最简单的一个方法,通过一个方法检查默认浏览器,然后通过传递参数来打开它。在窗体中可以是'mailto:aname@anaddress?subject=:::a subject',或者是一个网站地址"http://"或者"https://" uses LCLIntf; ... OpenURL('http://www.lazarus.freepascal.org');查找默认浏览器 在每个平台上面都有它不同的默认浏览器,在LCL unit lazhelphtml中保函了一个THTMLBrowserHelpViewer来启动一个浏览器来查看LCL帮助系统。你可以使用他的FindDefaultBrowser方法来查找默认浏览器,然后传递参数来启动他,例如:
uses
Classes, ..., LCLProc, LazHelpHTML;
...
implementation
procedure TMainForm.Button1Click(Sender: TObject);
var
v: THTMLBrowserHelpViewer;
BrowserPath, BrowserParams: string;
begin
v:=THTMLBrowserHelpViewer.Create(nil);
v.FindDefaultBrowser(BrowserPath,BrowserParams);
debugln([' ath=',BrowserPath,' Params=',BrowserParams]);
v.Free;
end;
给出的例子,在Linux中: Browser=/usr/bin/xdg-open Params=%s 在Windows中你可以获取: Browser=C:\windows\system32\rundll32.exe Params=url.dll,FileProtocolHandler %s
打开一个浏览器
你可以使用TProcessUTF8通过命令行来启动一个浏览器:
uses
Classes, ..., LCLProc, LazHelpHTML, UTF8Process;
...
implementation
procedure TMainForm.Button1Click(Sender: TObject);
var
v: THTMLBrowserHelpViewer;
BrowserPath, BrowserParams: string;
p: LongInt;
URL: String;
BrowserProcess: TProcessUTF8;
begin
v:=THTMLBrowserHelpViewer.Create(nil);
try
v.FindDefaultBrowser(BrowserPath,BrowserParams);
debugln([' ath=',BrowserPath,' Params=',BrowserParams]);
URL:='http://www.lazarus.freepascal.org';
p:=System.Pos('%s', BrowserParams);
System.Delete(BrowserParams,p,2);
System.Insert(URL,BrowserParams,p);
// start browser
BrowserProcess:=TProcessUTF8.Create(nil);
try
BrowserProcess.CommandLine:=BrowserPath+' '+BrowserParams;
BrowserProcess.Execute;
finally
BrowserProcess.Free;
end;
finally
v.Free;
end;
end;
内嵌浏览器组件到程序
使用Turbopower互联网控件
lazarus提供一个TurboPowerIPro包(lazarus/components/turbopower_ipro/turbopoweripro.lpk)保函下面功能:
[li]It contains a control to put onto a form. When you install the package in the IDE, you get some new components in the palette, so you can drop them onto a form just like any LCL control.[/li][li]It is written completely in Pascal and therefore works on all platforms out of the box without any extra installation.[/li][li]You have the full control, what files/urls are opened.[/li][li]It does not have all the features of a full webbrowser. No multimedia stuff, javascript or flash. This must be implemented by you.[/li] 同样里面保函一个查看html中保函图像和链接的例子 |
QT webkit
THtmlPort
THtmlPort is a Lazarus/Free Pascal version of Dave Baldwin's HTML Components, including THtmlViewer, TFrameViewer and TFrameBrowser.
GeckoPort
GeckoPort是一个为Lazarus/Free Pascal开发Takanori Ito's Gecko SDK的delphi版本, 保函TGeckoBrowse组件. CIT信息网原创翻译 |