Creating the Web browser application consists of the following steps:
- Create a VCL Form with a button control.
- Add a TWebBrowser component to the form.
- Add controls to enter a URL and launch the browser.
- Write the code to launch the browser when a button is clicked.
- Run the application.
To create a VCL Form
- Choose FileNewOtherDelphi Projects or C++Builder Projects and double-click the VCL Forms Application icon. The VCL Forms Designer is displayed.
- From the Internet page of the Tool Palette, place a TWebBrowser component on the form.
- With the TWebBrowser component selected on the form, drag the handles to adjust the size of the browser window. Leave some space on the form above the TWebBrowser to add a URL entry window. If the window is not large enough to display a browser page in its entirety, the TWebBrowser component adds scrollbars when you run the application and launch the browser window.
- From the Standard page of the Tool Palette, place a TMemo component on the form. With the TMemo component selected on the form, drag the handles to adjust the size to accommodate a user-entered URL.
- From the Standard page of the Tool Palette, place a Label component on the form.
- Select the Label, and in the Object Inspector, enter URL: as the Label caption.
- From the Standard page of the Tool Palette, place a TButton component on the form.
- Select the Button, and in the Object Inspector, enter OK as the TButton caption.
To code a button click event that launches the browser
- Select Button1 on the form.
- In the Object Inspector, double-click the OnClick action on the Events tab. The Code Editor displays, with the cursor in the Button1Click event handler block.
- Type the following code:
WebBrowser1.Navigate(WideString(Memo1.Text));
WebBrowser1–>Navigate( WideString( Memo1–>Text ) );
To run the application
- Choose RunRun to build and run the application.
- Enter a URL to a Web page in the memo window; then click the button. The browser launches in the TWebBrowser window.