Delphi Web page to create a program interface

Source: Internet
Author: User

As we all know, today's Web pages want to have more fancy, than the traditional Windows application interface monotonous menu plus button, I do not know how much eye-catching. and the Web page is very rich in material, production is relatively simple. If you want to be a gorgeous, dynamic program interface, the Web interface is your best choice.

The first step: according to need, with FrontPage or Dreamweaver to do an interface, interface plus pictures, but also add beautiful dynamic flash. The web interface is linked to program events with a "HYPERLINK", which we use as an example of a simple player program.

For example: To do a player, there are "play" button and "Stop" button, respectively set the "Play" button link to "Play_", "Stop" button hyperlink is "Stop_". and save this page file as "webfrm.htm".

Step Two: Create a new project in Delphi, set the Form1 width and just the same size as the Web page, place a WebBrowser1 control on the Form1, set the WebBrowser1 align property to alclient, We are using Twebbrowser to display the Web interface. The code is as follows:

procedure TForm1.FormCrea
teSender TObject
begin
WebBrowser1.Navigate'D\播放器\WebFrm.htm'//把“D\播放器”换成你保存WebFrm.htm的目录
end

Step three: The key is in this step. In response to the "play" and "Stop" click events on the Web interface, the Twebbrowser OnBeforeNavigate2 event is used, and its code is as follows:

procedure TForm1.WebBrowser1BeforeNa
vigate2Sender TObject
const pDisp IDispatch var URL Flags TargetFrameName PostData
Headers OleVariant var Cancel WordB ool

In its seven parameters, we will use both the URL and cancel parameters, in this case, when you click the "Play" button, the URL will return to the "d\ player \webfrm.htm\play_" the line string  when the "Stop" button is clicked, the URL returns "D\ player \ Webfrm.htm\stop_ "This line string. The purpose of this argument is: When you click on the "Play" button, the web wants to jump to the "d\ player \webfrm.htm\play_" This page, but there is no this page, WebBrowser1 will appear we often see the Internet "This page can not show" this page, When you set Cancel to Truewebbrowser1, the link will be disconnected and the above situation will not occur.

The specific code is as follows:

procedure TForm1.WebBrowser1BeforeNa
vigate2Sender TObject
const pDisp IDispatch var URL Flags TargetFrameName PostData
Headers OleVariant var Cancel WordB
ool
begin
if Pos'Play_' URL > 0 then begin //当返回的URL含有“Play_”,就执行播放的代码
ShowMessage'播放'//为简单起见,用来代替播放的代码。
Cancel = True
end
else
if Pos'Stop_' URL > 0 then begin
ShowMessage'停止'//为简单起见,用来代替播放的代码。
Cancel = True
end
end

(The code above delphi6+win2000 compiled.) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.