简体   繁体   English

加载默认的URL delphi

[英]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. 我想在表单创建事件中加载默认URL,我可以使用按钮单击来加载URL,但是我希望它在应用程序加载时加载URL,在我运行程序时它不会加载该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. 

What you report is not the whole story. 您报告的内容并非全部。 Take the following steps: 请执行以下步骤:

  1. Create a new VCL forms project. 创建一个新的VCL表单项目。
  2. Add a TWebBrowser component to the automatically generated form. TWebBrowser组件添加到自动生成的表单中。
  3. Double click on the form to create an OnCreate event handler named FormCreate that is associated with the OnCreate event. 在窗体上双击创建OnCreate命名事件处理程序FormCreate与该关联OnCreate事件。
  4. Put your call to WebBrowser1.Navigate into the body of the FormCreate method. FormCreate WebBrowser1.Navigate的调用放入FormCreate方法的主体中。
  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 . 也许OnCreate事件处理程序未分配给FormCreate Or perhaps something else is wrong. 也许还有其他问题。 However, you can follow the steps above to prove to yourself that navigating from OnCreate works. 但是,您可以按照上述步骤向自己证明从OnCreate导航是OnCreate 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. 最重要的是,从OnCreate事件调用Navigate足以在表单启动时显示网页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM