Showing Help with the TWebBrowser Component in Delphi 7

In order to obtain the following screenshot we executed the program, checked two boxes for the formatting, clicked on the help button, followed the link to the browser help file then clicked on the right arrow to obtain our helpful message.

Output from program BrowserDemo

Output from program BrowserDemo

The essential code of the files needed for program BrowserDemo follows. You can download the five Delphi files, three HTML help files and three images in this zip file.

uMain.pas

unit uMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmMain = class(TForm)
    btnHelp: TButton;
    chkItalic: TCheckBox;
    chkBold: TCheckBox;
    chkUnderline: TCheckBox;
    btnNew: TButton;
    lblTip: TLabel;
    procedure btnHelpClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnNewClick(Sender: TObject);
    procedure chkItalicClick(Sender: TObject);
    procedure chkBoldClick(Sender: TObject);
    procedure chkUnderlineClick(Sender: TObject);
  end;

var
  frmMain: TfrmMain;

implementation
{$R *.dfm}
uses
  uBrowserDemo;
type
  TTip = set of 1 .. 5;
const
  Tips : array[1 .. 5] of string = ('Remember your semicolons.',
                                    'There must not be a semicolon just before else.',
                                    'A variable must have a different identifier than your program.',
                                    'Use meaningful identifiers.',
                                    'Format your code.');
var
  CurrentTip : integer;
  TipSet : TTip = [];

procedure TfrmMain.btnHelpClick(Sender: TObject);
begin
  //Concatenate path of project directory with filename to give pathname
  frmWebBrowser.WebBrowser1.Navigate(ExtractFilePath(ParamStr(0)) + 'MainHelp.html');
  frmWebBrowser.Show;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  randomize;
  lblTip.Font.Style := [];
  CurrentTip := random(5) + 1;
  include (TipSet, CurrentTip);
  lblTip.Caption := Tips[CurrentTip];
end;

procedure TfrmMain.btnNewClick(Sender: TObject);
begin
  if TipSet = [1, 2, 3, 4, 5] then
    begin
      showMessage('You have seen them all!');
      TipSet := [];
    end
  else
    repeat
      CurrentTip := random(5) + 1;
    until not (CurrentTip in TipSet);
  include (TipSet, CurrentTip);
  lblTip.Caption := Tips[CurrentTip];
end;

procedure TfrmMain.chkItalicClick(Sender: TObject);
begin  
  if chkItalic.Checked then
    lblTip.Font.Style :=  lblTip.Font.Style + [fsItalic]
  else
    lblTip.Font.Style :=  lblTip.Font.Style - [fsItalic];
end;

procedure TfrmMain.chkBoldClick(Sender: TObject);
begin
  if chkBold.Checked then
    lblTip.Font.Style :=  lblTip.Font.Style + [fsBold]
  else
    lblTip.Font.Style :=  lblTip.Font.Style - [fsBold];
end;

procedure TfrmMain.chkUnderlineClick(Sender: TObject);
begin
  if chkUnderline.Checked then
    lblTip.Font.Style :=  lblTip.Font.Style + [fsUnderline]
  else
    lblTip.Font.Style :=  lblTip.Font.Style - [fsUnderline];
end;

end.

uMain.dfm

object frmMain: TfrmMain
  Left = 331
  Top = 243
  Width = 644
  Height = 169
  Caption = 'Main Form'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 120
  TextHeight = 16
  object lblTip: TLabel
    Left = 24
    Top = 88
    Width = 6
    Height = 23
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
  end
  object btnHelp: TButton
    Left = 568
    Top = 0
    Width = 57
    Height = 25
    Caption = 'Help'
    TabOrder = 0
    OnClick = btnHelpClick
  end
  object chkItalic: TCheckBox
    Left = 16
    Top = 8
    Width = 97
    Height = 17
    Caption = 'Italic'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
    OnClick = chkItalicClick
  end
  object chkBold: TCheckBox
    Left = 16
    Top = 32
    Width = 97
    Height = 17
    Caption = 'Bold'
    TabOrder = 2
    OnClick = chkBoldClick
  end
  object chkUnderline: TCheckBox
    Left = 16
    Top = 56
    Width = 97
    Height = 17
    Caption = 'Underline'
    TabOrder = 3
    OnClick = chkUnderlineClick
  end
  object btnNew: TButton
    Left = 144
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Change tip'
    TabOrder = 4
    OnClick = btnNewClick
  end
end

uBrowserDemo.pas

unit uBrowserDemo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls, OleServer, Buttons;

type
  TfrmWebBrowser = class(TForm)
    WebBrowser1: TWebBrowser;
    bbtnBack: TBitBtn;
    bbtnForward: TBitBtn;
    btnSearch: TButton;
    procedure bbtnBackClick(Sender: TObject);
    procedure bbtnForwardClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure btnSearchClick(Sender: TObject);
  end;

var
  frmWebBrowser: TfrmWebBrowser;

implementation

{$R *.dfm}

procedure TfrmWebBrowser.bbtnBackClick(Sender: TObject);
begin
  try
    //Go back to the previous page in the history list.
    Webbrowser1.GoBack;
  except
    ShowMessage('Nothing to go back to');
  end;
end;

procedure TfrmWebBrowser.bbtnForwardClick(Sender: TObject);
begin
  try
    //Go forward to the next page in the history list.
    Webbrowser1.GoForward;
  except
    ShowMessage('Nothing to go forward to');
  end;
end;

procedure TfrmWebBrowser.FormResize(Sender: TObject);
begin
  WebBrowser1.Width := frmWebBrowser.ClientWidth;
  WebBrowser1.Height := frmWebBrowser.ClientHeight - 30;
end;

procedure TfrmWebBrowser.btnSearchClick(Sender: TObject);
begin
  //Open the registered search page
  Webbrowser1.GoSearch;
end;

end.

uBrowserDemo.dfm

object frmWebBrowser: TfrmWebBrowser
  Left = 595
  Top = 220
  Width = 537
  Height = 592
  Caption = 'Web Browser'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -14
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnResize = FormResize
  PixelsPerInch = 120
  TextHeight = 16
  object WebBrowser1: TWebBrowser
    Left = 0
    Top = 24
    Width = 513
    Height = 517
    TabOrder = 0
    ControlData = {
      4C0000006B2A0000BF2A00000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object bbtnBack: TBitBtn
    Left = 4
    Top = 0
    Width = 25
    Height = 25
    Hint = 'Go backwards through the history list'
    ModalResult = 4
    ParentShowHint = False
    ShowHint = True
    TabOrder = 1
    OnClick = bbtnBackClick
    Glyph.Data = {
      36050000424D3605000000000000360000002800000015000000140000000100
      1800000000000005000074120000741200000000000000000000FE0200FE0200
      FE0200FC0200FB0200F70200F20201EE0301E60001E20001E40409DE0307DF07
      0CE40E13DA060CDF0206F50102FE0000FE0000FE0000FE000000FE0200FE0200
      FE0200FC0200F90300F50300F00300EB0302F00E0FE20507CF0000DE0B0FD90C
      0FC40000CA0105D90308F20102FE0000FE0000FE0000FE000000FE0300FE0300
      FE0300FC0300F90300F20300EC0400E30402CC0000E31313C80001CE0E0FC60B
      0DB40001CE1B1EC80305EC0202FE0000FE0000FE0000FE000000FE0200FE0200
      FE0200FC0300F90300F20300E50401D00704B50F0AFFBAB4FFECE8FFF0ECFFEE
      EEFFECEEFFE1E6FF5257F00202FE0000FE0000FE0001FE000100FF0404F30000
      FF0200FA0000FE0300F70805D40000AA0803FFCABDFFFEEEFFF9EBFFF9EDFFF7
      F2FFC3C5C50005F70510F80001FE0000FF0304FE0002FE000400E70000FF1313
      FF0B09EF0000EE0000DC0400A40000FFD4C9FFE9DBFFFFF4FFFFF7FFF9F3FFC4
      C5A60913ED0B1CFC0009F90000F70000F80000FA0000FA000000FF1D1AD30000
      E50100EA0B03E60803B60900FFDBC8FFF2DFFFFDF4FFFAF8FFE7E9FFC7D0BA06
      18D70009F60012E90000FC0C01F50A00F70800FD0B00F8000000EC0300E30500
      D50700C60E00B8190BFFBFAEFFF2DCFFFFF2FFFEF8FFE7EBFFD1DB720311AC0A
      1CC40919C2040FCD1214B50200B50400BF0800D0110EC1000000F30000F21408
      CC17078C1000FFE6C9FFFFEAFFFFECF9FDF1F2F6F1FFFDFFFFFAFFFFF9FFFFF9
      F9FFFDF7FFFDF2FFECE3FFF7F9FFF4FEFFF1FFFFE8FDFFA4C400FB0000D40000
      FB503BFFF2D7FFFFE0FBFFEBFFFFF1FFFFF9EDFBFAF4FFFFF5ECF6FFFDFFEDFF
      FCD6F6E5F3FFF2FBFFF5FFF8FDFFF3FFFFF1FFFFEFFFDAA1C800FF0600FE1B0C
      BC0400FFF6DEFFFFE6FFF7E0FFFFF5F6EFECFBFEFFEFEEF8FFFAFFFFFBFFEBF2
      EFF6FFF8FBFFF1F9FCECFFFEFFFFF9FFFFF6FFFFF3FFDAA1C200FF0B00E50000
      D90D00AC0A00FFDACAFFFBEEFFF2EDFFFDFEFDF0F8FFF9FFFFF3FFFFF7FFFFF1
      F8FFF9F7FFF0E6FFFBF1FFF8F8FFF4F9FFF0F8FFF1FFFF9DB200FF0900F40000
      F60C00DF0600D81713FFA7A4FFF8F5FFFBFCFFF9FFFFF6FFF4BDD06F15289300
      10C70F1FBC0008BF0608B50A08B40B07B90908C20709CB050B00F40000FF0B02
      FF0700EE0000F30909D01314FFB3B3FFF8F8FFF5FCFFF7FFFFEDFAFFC5D4B70E
      21DD0216FD0719F90008EC0204E90401EC0301F20201F9010100F90300F90000
      FC0200FF0B07DD0000D40605B81415FFABABFFF7F5FFFDFCFFFDFCFFF6F8FFB8
      BEA40006E2000BF30000F90007F70005F90005FB0004FC000400F10200F90806
      F00000F90000FF201BD70000C70000B91D1DFFCCC6FFF2EBFFE6E0FFF8F4FFF5
      F4FFCECFD4050DFF0C16F90007FC0005FC0005FC0004FB000400E10000EC0402
      F30000F60000FF0B06EE0000EE0E09BF01008D0100FFD4CDFFF7F0FFF1ECFFF3
      F0FFE1DEFFE5E4FF5050EC0202F70200F70200F70200F5030000EF0A0DDF0000
      FE0605FF0C07E20000FF170DEA0000EB1007D4170FA50000AA110EAC1615AB0E
      0BB10706C00605DB0C0AEC0301F70200F70200F70200F5030000FB010CFB0007
      F90000FE0200FF1409E40000FF1A0CE70000E50000E60502E90C0ED80000D600
      00F51419D80000ED0406F50101FC0100FC0100FB0100FB010000FA0005FD0006
      FF0003FD0100F80000FF1203F70000FF0A00FF0801FB0000FF0309FC0003FE00
      07F90005F20002F40003FB0002FE0001FE0001FE0001FC000100}
    Margin = 0
    Spacing = 0
  end
  object bbtnForward: TBitBtn
    Left = 33
    Top = 0
    Width = 25
    Height = 25
    Hint = 'Go forward through the history list'
    ModalResult = 4
    ParentShowHint = False
    ShowHint = True
    TabOrder = 2
    OnClick = bbtnForwardClick
    Glyph.Data = {
      36050000424D3605000000000000360000002800000015000000140000000100
      1800000000000005000074120000741200000000000000000000F10000F00000
      F00000F10000F30505EC0202E50000E70302D50000E00000ED0C0ADF0000EB05
      04E40000F10908F90B0AF90101FE0000FE0000FE0000FE000000FF090BFD0406
      FF080AF70607E20000DD0200DA0703CB0000DC0F0AD80A05DB0804E10603DF00
      00EE0404F00404E50000FB0001FE0000FE0000FE0000FE000000F30000F10000
      FF090CF70909C80000C60901CE2419B21206B01004B10A00C10A01DE130ECA00
      00F70607FF0F11FD0203FC0001FE0000FE0000FE0000FE000000FF0909F60000
      FF0405F20100D90200FF625FFFD3CEFFEEE7FFF4EAFFF5EAFFEBE1FFBBB3D11B
      15D80300EF0000F90000FE0000FE0000FE0000FE0000FC010000FC0400FC0300
      F20000FC0403F90A0DD10000CF0F1AFFB9C2FFF3F7FFEDEBFFFEF4FFF9EBFFBB
      ABB21C0BE10D00FF0A00FC0200FF0202F10000FF0403FF0D0C00F40000FF0E09
      FF0D09F50000EC0000F1000FC80001C00F22FFBDCCFFF6FCFFFFF9FFFFF5FFF9
      E5FFC5AD990000E21101E60000EE0000FF1311EA0000EA000000FF000AF20002
      F30009F80710EE0002FF1020F10010CB0001B0000DFFCAD6FFF1F0FFFFF7FFFF
      F4FFFFEEFFC7B59C1205CF150BD10000D70000FF1D1AF1000000D50016BF0008
      B4000AC2141CB00005B90409BD020BC20E19B315217F0F17F8CCCDF9F5F0FDFF
      F9FFFFF6FFF4EDFFC5BDA50F04CB1106D70A02E10100EC000000FFB4CEFFEDFF
      FFF4FCFFFAF7FFF9EDFFFFF0FFF9EBFFFDF1FFEDE5FFF8F3FFF8F5FFFFFFFFFA
      FBFFFAFFFFF5FEFFE4E8FFE1D5A00A00C10B00DF0E06FF151200D493A9FFECFC
      FFF6F9F8FBF2F4FFF5F1FFF1EEFFE9FAFFF1FBFFF5FBFFF9EFF8F5FCFEFFFFF5
      FBFFF8FFFFF3FFFFF4F9FFF5E9FFF5E2F94E40C70000EE010000E1B9C5FFF8FF
      FFFAFCFFFFF9FFFFF5FFFFF4FDFDEDFFFFF5F7FAF1E8EEE9FAFFFFFDFFFFFFFA
      FFFFFBFFFFF9FFFFF5F4FFF4E6FFDCCAC21306D90C04E6000000EEA6ACFFF2F6
      FFF6F8FFF7F5FFECE9FFF8F4FFF7F7FFF4F6FFF9FCFFFBFFFFF8FBFDFFFFFFFF
      FEFFF9F5FFFFF7FFF9EFFFE6D8AC0500C90D02D50100F60B0800AA0508AF080B
      BA0D11C50F17C4020EC60010CE031CAD00148C021A691023DCBDC6FDFFFEF8FF
      F7FFFFF1FFFFEBFFBFA9AE0F01D50800DC0700E30500EC040000EE110DD20000
      E00000E60000F50008FF051FF00017D4001DA90927FFC9DFFFF8FFFFFFF9FFFF
      F1FFFDE2FFC3A4941B01CC0B00EC0400EC0400EC0400EE030000E80000FF150A
      FB0701FF1111FF020EDA0000D40016B0051FFFC7DBFFDBE8FFFAFEFFFDF5FFF6
      E4FFCEB6B41500DD1500EC0500F90100F90100F50200F2030000FE0500FA0100
      F30000E80000FF0D12E00006CA0F1EFFC4D1FFF1FCFFF5FCFFF8F8FFF7F2FFBE
      B3B00400DE0600EC0000FC0300FE0000FE0000FB0100F7020000FF0801FF0500
      FF0902FF0F0BEA0000FF5B5CFFECEBFFDFDEFFF4F4FFF4F4FFDDDEFFB7B7C807
      04F81B13E80000FF1709FE0200FE0000FE0000FC0100FC010000FF0809E90000
      FD0302F00000E40000DD0902B40400B31D13970B059A0907C4171BCB0206EC04
      0AF80103F60100E80000F50300F70200FB0100FC0100FE000000F10000FF0A15
      F60307F70C09F20F06DF0200E50A00DD0500D60000E90F10ED0A0FE40000F400
      09E40000FA0D11E90302E30501E70500F30200FB0100FC010000FB000BFC000E
      F30008E00000E20400ED0C00F20100FE0600FF0E0BE70000FB0002FF040EF700
      07EF0006F1060EE10204DB0602E00600F00300FB0100FC010000}
    Margin = 0
    Spacing = 0
  end
  object btnSearch: TButton
    Left = 112
    Top = 0
    Width = 81
    Height = 25
    Caption = 'Search'
    TabOrder = 3
    OnClick = btnSearchClick
  end
end

BrowserDemo.dpr

program BrowserDemo;

uses
  Forms,
  uBrowserDemo in 'uBrowserDemo.pas' {frmWebBrowser},
  uMain in 'uMain.pas' {frmMain};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TfrmMain, frmMain);
  Application.CreateForm(TfrmWebBrowser, frmWebBrowser);
  Application.Run;
end.
Programming - a skill for life!

How to provide help in Delphi and Lazarus applications