Sign in Join
Wiki copytemporary

Webbrowser

Deutsch · English · Español · Русский

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.

Starting a web browser to show a page/URL

OpenURL

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:///'.

pascal
uses LCLIntf;
    ...
    OpenURL('http://www.lazarus.freepascal.org');

Finding the default web browser

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.

You can use its method FindDefaultBrowser to find the default browser and the parameter to start. For example:

pascal
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('Browser=',BrowserPath,' Params=',BrowserParams);
      v.Free;
    end;

This gives for example under Ubuntu (Linux):

pascal
Browser=/usr/bin/xdg-open Params=%s

Under Windows:

pascal
Browser=C:\windows\system32\rundll32.exe Params=url.dll,FileProtocolHandler %s

Under macOS:

pascal
Browser=/usr/bin/open Params="%s"

Starting the browser

Once you know the command line and parameters you can use TProcessUTF8 to start the browser:

pascal
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(['Path=',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;

Integrate web browser component in application

TurboPower Internet Pro

Lazarus provides the package TurboPowerIPro (lazarus/components/turbopower_ipro/turbopoweripro.lpk) with the following features:

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.

Read more TurboPower Internet Pro

WebView4Delphi

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.

There are a few things pending like the "windowless mode".

TWebBrowser WebKit (macOS Cocoa)

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 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.

QT Webkit

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.

THtmlPort

THtmlPort is a Lazarus/Free Pascal version of Dave Baldwin's HTML Components, including THtmlViewer, TFrameViewer and TFrameBrowser.

HtmlViewer

The HtmlViewer component for Delphi and Lazarus, set consists of:

fpCEF3

fpCEF3 is a Chromium Embedded Framework for Free Pascal.

CEF4Delphi

CEF4Delphi is updated Chromium Embedded Framework, which supports Lazarus.

GeckoPort

GeckoPort is a Lazarus/Free Pascal version of Takanori Ito's Gecko SDK for Delphi, including the TGeckoBrowser component.

LazActiveX

LazActiveX allows to import MS Internet Explorer type library.

LazWebkit

LazWebkit 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.

See also


From the Free Pascal wiki, page "Webbrowser", as the Internet Archive kept it on 2026-01-31, last changed on 2025-04-29. 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.

Revision 3, last changed by WikiArchive .

Edited on wiki.freepascal.org by 13 people, 2012–2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
Aguila3000moved Webbrowser to Webbrowser/es: Traducción al español
Aguila3000Redirected page to Webbrowser
Aguila3000Redirected page to Webbrowser/es
Aguila3000
Aguila3000
BigChimpTypos, grammar (minor)
TheodpIntegrate web browser component in application
TheodpIntegrate web browser component in application
TheodpIntegrate web browser component in application
TheodpIntegrate web browser component in application
TheodpIntegrate web browser component in application
Jwdietrichcategorization
MichlIntegrate web browser component in application: fpCEF added
Jc99Webbrowser was also used in Delphi to retrieve HTTP-content, so here is the link to the FCL-alternative (minor)
ArentUsing the Turbopower internet pro control
Arent
Avraadded fpbrowser (minor)
Avraadded networking category (minor)
TrevFixed syntax highlighting (minor)
TrevSee also: Added entry (minor)
Zaheradd HTMLViewer
MartinfpCEF3
TrevIntegrate web browser component in application: Added TWebBrowser WebKit for macOS Cocoa
TrevSee also: Add link + External links: New section
AlextpUsing the Turbopower internet pro control
Alextpwebview4delphi
AlextpUsing the TurboPower Internet Pro control
AlextpTHtmlPort
AlextpHtmlViewer
AlextpfpCEF3
AlextpCEF4Delphi
AlextpGeckoPort
AlextpLazActiveX
AlextpLazWebKit
AlextpQT Webkit
AlextpWebView4Delphi
AlextpUsing the TurboPower Internet Pro control
AlextpWebView4Delphi
AlextpWebView4Delphi
TrevFinding the default web browser: Fix typo; fix inconsistent output; add macOS output
TrevFinding the default web browser: Fix my typo :-
PierceNgAdd fpwebview

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.