Sign in Join
Wiki copytemporary

Webbrowser: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Webbrowser

OldNewLine
1+This page summarizes various ways to display HTML pages from a Pascal program, ranging from calling an external browser to adding a component capable of rendering the html page into a form.
2+
3+## Starting a web browser to show a page/URL
4+
5+### OpenURL
6+
7+OpenURL is simplest way of opening URLs in general. This procedure will detect the default web browser and open URL from parameter in it. It can be used for mail addresses of the form 'mailto:aname@AnAddress?subject=:::A subject line', web addresses 'http://' and files 'file:///'.
8+
9+``` pascal
10+uses LCLIntf;
11+...
12+OpenURL('http://www.lazarus.freepascal.org');
13+```
14+
15+### Finding the default web browser
16+
17+Every platform has a mechanism for its default web browser. The LCL unit **lazhelphtml** contains a class [[THTMLBrowserHelpViewer]] to start a web browser for the LCL help system.
18+
19+You can use its method FindDefaultBrowser to find the default browser and the parameter to start. For example:
20+
21+``` pascal
22+uses
23+ Classes, ..., LCLProc, LazHelpHTML;
24+
25+...
26+
27+implementation
28+
29+procedure TMainForm.Button1Click(Sender: TObject);
30+var
31+ v: THTMLBrowserHelpViewer;
32+ BrowserPath, BrowserParams: string;
33+begin
34+ v:=THTMLBrowserHelpViewer.Create(nil);
35+ v.FindDefaultBrowser(BrowserPath,BrowserParams);
36+ debugln('Browser=',BrowserPath,' Params=',BrowserParams);
37+ v.Free;
38+end;
39+```
40+
41+This gives for example under Ubuntu (Linux):
42+
43+`Browser=/usr/bin/xdg-open Params=%s`
44+
45+Under Windows:
46+
47+`Browser=C:\windows\system32\rundll32.exe Params=url.dll,FileProtocolHandler %s`
48+
49+Under macOS:
50+
51+`Browser=/usr/bin/open Params="%s"`
52+
53+### Starting the browser
54+
55+Once you know the command line and parameters you can use [[TProcessUTF8]] to start the browser:
56+
57+``` pascal
58+uses
59+ Classes, ..., LCLProc, LazHelpHTML, UTF8Process;
60+
61+...
62+
63+implementation
64+
65+procedure TMainForm.Button1Click(Sender: TObject);
66+var
67+ v: THTMLBrowserHelpViewer;
68+ BrowserPath, BrowserParams: string;
69+ p: LongInt;
70+ URL: String;
71+ BrowserProcess: TProcessUTF8;
72+begin
73+ v:=THTMLBrowserHelpViewer.Create(nil);
74+ try
75+ v.FindDefaultBrowser(BrowserPath,BrowserParams);
76+ debugln(['Path=',BrowserPath,' Params=',BrowserParams]);
77+
78+ URL:='http://www.lazarus.freepascal.org';
79+ p:=System.Pos('%s', BrowserParams);
80+ System.Delete(BrowserParams,p,2);
81+ System.Insert(URL,BrowserParams,p);
82+
83+ // start browser
84+ BrowserProcess:=TProcessUTF8.Create(nil);
85+ try
86+ BrowserProcess.CommandLine:=BrowserPath+' '+BrowserParams;
87+ BrowserProcess.Execute;
88+ finally
89+ BrowserProcess.Free;
90+ end;
91+ finally
92+ v.Free;
93+ end;
94+end;
95+```
96+
97+## Integrate web browser component in application
98+
99+### TurboPower Internet Pro
100+
101+Lazarus provides the package TurboPowerIPro (lazarus/components/turbopower_ipro/turbopoweripro.lpk) with the following features:
102+
103+- 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.
104+- It is written completely in Pascal and therefore works on all platforms out of the box without any extra installation.
105+- You have the full control, what files/urls are opened.
106+- It does not have all the features of a full webbrowser. No multimedia stuff, javascript or flash. This must be implemented by you.
107+
108+There are some examples in lazarus/components/turbopower_ipro/examples demonstrating how to open a local html file with some images, hyperlinks and history buttons. See the [[IPro tab]] on the [[Component Palette]].
109+
110+### WebView4Delphi
111+
112+[[WebView4Delphi]] allows to embed Chromium-based web browsers in your Delphi or Lazarus applications using the WebView2 runtime. It uses many of the tricks from CEF4Delphi and you will notice many similarities if you used it.
113+
114+There are a few things pending like the "windowless mode".
115+
116+### TWebBrowser WebKit (macOS Cocoa)
117+
118+TWebBrowser control is implemented only for the LCL Cocoa widgetset for macOS by wrapping the WebView class that's part of every Mac's WebKit framework. Note that by default macOS blocks calls to insecure HTTP sites. You can relax this restriction by setting the *NSAllowsArbitraryLoads* key in your application's [[macOS property list files|Info.plist]] file, but for testing you might stick with HTTPS sites. This control does not add any bulk to your app and does not require installation of any additional libraries. Everything it needs is already on your Mac and is accessible via the FPC CocoaAll unit. [Source](https://macpgmr.github.io/MacXPlatform/lclwebbrowser-src.zip).
119+
120+### QT Webkit
121+
122+When using the Qt widgetset, you can use the Qt Webkit to embed a browser into a LCL form. Lazarus demo is available on [FPC Qt4 Binding Web Page](http://users.telenet.be/Jan.Van.hijfte/qtforfpc/fpcqt4.html).
123+
124+### THtmlPort
125+
126+[[THtmlPort]] is a Lazarus/Free Pascal version of Dave Baldwin's HTML Components, including THtmlViewer, TFrameViewer and TFrameBrowser.
127+
128+### HtmlViewer
129+
130+The [HtmlViewer](https://github.com/BerndGabriel/HtmlViewer) component for Delphi and Lazarus, set consists of:
131+
132+- THtmlViewer
133+- TFrameViewer
134+- TFrameBrowser
135+
136+### fpCEF3
137+
138+[[fpCEF3]] is a Chromium Embedded Framework for Free Pascal.
139+
140+### CEF4Delphi
141+
142+[[CEF4Delphi]] is updated Chromium Embedded Framework, which supports Lazarus.
143+
144+### GeckoPort
145+
146+[[GeckoPort]] is a Lazarus/Free Pascal version of Takanori Ito's Gecko SDK for Delphi, including the TGeckoBrowser component.
147+
148+### LazActiveX
149+
150+[[LazActiveX]] allows to import MS Internet Explorer type library.
151+
152+### LazWebkit
153+
154+[LazWebkit](http://sourceforge.net/p/lazwebkit/wiki/Home/) is a project focused to provide browser and composer web content features for Lazarus IDE based projects. Currently it's implemented only for GTK2 widgetset.
155+
156+## See also
157+
158+- [[Executing External Programs]]
159+- [[fphttpclient]] Part of fcl-web that can be used stand-alone to retrieve HTTP-Content
160+- [[fpbrowser]] web browser written in Lazarus
161+- [[fpwebview]] cross-platform library for Linux, macOS and Windows for building desktop applications using Pascal and web technology
162+- [[Windows Programming Tips|Using Windows native WinInet for web retrieval]]
163+- [[macOS NSURLSession]] - the replacement for [[macOS NSURLConnection|NSURLConnection]] for web retrieval.
164+
165+---
166+*From the Free Pascal wiki, page "Webbrowser", as it stood on 2022-02-18 after a change by PierceNg, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history