LowFormat
LowFormat

Reputation: 3

load a default url delphi

i would like to load a default URL on form create event, i can load a url using a button click but i want it to load the URL when the app loads, when i run the program it wont load the url.

here is my code :

 unit launcher;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.pngimage, Vcl.ExtCtrls,
  Vcl.StdCtrls, Vcl.OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    WebBrowser1: TWebBrowser;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

 procedure TForm1.FormCreate(Sender: TObject);
  begin
 Webbrowser1.Navigate('http://www.digitalxeon.net');
 end;

procedure TForm1.Button1Click(Sender: TObject);
close;
end;

end. 

Upvotes: 0

Views: 270

Answers (1)

David Heffernan
David Heffernan

Reputation: 613542

What you report is not the whole story. Take the following steps:

  1. Create a new VCL forms project.
  2. Add a TWebBrowser component to the automatically generated form.
  3. Double click on the form to create an OnCreate event handler named FormCreate that is associated with the OnCreate event.
  4. Put your call to WebBrowser1.Navigate into the body of the FormCreate method.
  5. Run your application and observe that the browser control displays your page.

In other words, something else in your application is blocking this. Perhaps the OnCreate event handler is not assigned to FormCreate. Or perhaps something else is wrong. However, you can follow the steps above to prove to yourself that navigating from OnCreate works. Then all the remains is to diagnose where your application differs.

The bottom line is that calling Navigate from an OnCreate event is sufficient to show a web page on form startup.

Upvotes: 3

Related Questions