This article Reprinted from: http://blog.csdn.net/yushanddddfenghailin/article/details/17250967
Next we will introduce how to add buttons on the custom page. The button belongs to the tbutton class, which inherits from tbuttoncontrol. The class is defined as follows:
Tbutton = Class (tbuttoncontrol)
Property cancel: Boolean; read write;
Property caption: string; read write;
Property default: Boolean; read write;
Property Font: tfont; read write;
Property modalresult: longint; read write;
Property onclick: tpolicyevent; read write;
End;
Its Inheritance relationships include:
Next, we will add a button on a created custom page:
[Setup] Appname = test Appvername = test Defaultdirname = "E: \ test" Appversion = 1.0 [Files] Source: "F: \ Desktop \ test \ ipmsg.exe"; flags: dontcopy [Code] VaR Mypage: twizardpage; Mybtn: tbutton; Procedure initializewizard (); Begin Mypage: = createcustompage (wpwelcome, 'title: Custom page', 'description: This is my custom page '); Mybtn: = tbutton. Create (NiL ); Mybtn. Parent: = mypage. surface; End; |
First, explain the meaning of this Code.
The first is mybtn: = tbutton. create (NiL); Statement, which uses the member function create of the tbutton class to create an instantiated tbutton object. Here, the object is obtained using mybtn, And the NIL parameter is null, another similar statement is mybtn: = tbutton. create (mypage); Generally, you do not need to consider the differences between the two statements. The parameter of this function determines who will release the created control. nil, this button is not released when the program is closed or the form is closed. If it is nil, it needs to be released manually. If it is set to a page, the page is automatically released when it is released.
The other is the parent attribute of mybtn, which inherits from the twincontrol class. This attribute specifies the container containing this component. The buttons can only be displayed and moved in the specified package container.
When the installer is running on the custom page, the following window appears:
At this time, the button does not have a title, and the clicking does not respond, because the above Code does not add corresponding properties and events for it.
The following code will improve the above example (only the code segment is modified ):
[Code] VaR Mypage: twizardpage; Mybtn: tbutton; Myfont: tfont; Procedure clickmybtn (Sender: tobject ); Begin Msgbox ('you have clicked the button ~~ ', Mbinformation, mb_ OK ); End; Procedure initializewizard (); Begin Mypage: = createcustompage (wpwelcome, 'title: Custom page', 'description: This is my custom page '); Mybtn: = tbutton. Create (mypage ); Mybtn. Parent: = mypage. surface; Mybtn. Caption: = 'click me ~ '; Mybtn. Default: = true; Myfont: = tfont. Create (); Myfont. Size: = 16; Myfont. Style: = [fsbold]; Myfont. Style: = myfont. Style + [fsitalic]; (* Or use Myfont. Style: = [fsbold, fsitalic]; *) Mybtn. Font: = myfont; Mybtn. Width: = 300; Mybtn. Height := 100; Mybtn. onclick: [email protected]; End; |
Here, a new tfont instance myfont is created. This object mainly sets attributes such as the size, color, and bold of characters displayed on the object. Caption sets the text displayed in the button. The default attribute indicates that the button is selected by default, followed by the display text attribute, and the last width and height sets the button size, these two attributes are inherited from tcontrol, and finally the Event Response Function of the button. When the button is clicked, The clickmybtn process is executed. This process is also implemented before, note that the implemented code must be placed before calling this process; otherwise, the Code cannot be compiled. The running effect is as follows:
In addition, buttons have some attributes, such as top and left, which control the button's position. You can test them.