Modify VCL source Code Implementation Custom Input dialog box

Source: Internet
Author: User

Customizing the Input dialog box by modifying the VCL source code

In BCB, there are two functions to implement the input dialog: InputBox and Inputquery, in fact InputBox is also called inputquery, this function has several disadvantages:

(1). The button on the Input dialog box is in English.

(2). Cannot implement the effect of the asterisk password.

However, this problem is often encountered in practical programming. All Chinese interfaces and prompts, but in the input dialog box is the English button, some of the uncoordinated, and sometimes in the Win2K under the program, in Win98, the Input dialog box prompts will show incomplete. Usually in a form, you can change the default font to the Arial 9th number, but could you do it in the input dialog box? The answer is yes, the method is: Modify the VCL source!

The following methods introduce a custom input dialog box by modifying the VCL source code in the BCB 6.0 Enterprise Edition.

1. Locate the Dialogs.pas in the SOURCE\VCL directory of the BCB6 installation directory and copy a copy to your engineering directory.

2. Open the Dialogs.pas you just copied, and modify the Inputquery function code (1857-1927 lines):

The modified code is as follows:

function Inputquery (const acaption, aprompt:string;
var value:string): Boolean;
Var
Form:tform;
Prompt:tlabel;
Edit:tedit;
Dialogunits:tpoint;
Buttontop, Buttonwidth, Buttonheight:integer;
Begin
Result: = False;
Form: = tform.create (application);
With Form do
Try
Font.Name: = ' song body '; Change the font for the input dialog form to Arial
Font.Size: = 9; Change the font size of the input dialog form to number 9th
Canvas.font: = Font;
Dialogunits: = Getavecharsize (Canvas);
BorderStyle: = Bsdialog;
Caption: = acaption;
ClientWidth: = MulDiv (180, dialogunits.x, 4);
Position: = Poscreencenter;
Prompt: = Tlabel.create (Form);
With Prompt do
Begin
Parent: = Form;
Caption: = aprompt;
Left: = MulDiv (8, dialogunits.x, 4);
Top: = MulDiv (8, DIALOGUNITS.Y, 8);
Constraints.maxwidth: = MulDiv (164, dialogunits.x, 4);
WordWrap: = True;
End
Edit: = Tedit.create (Form);
With Edit do
Begin
Parent: = Form;
Left: = Prompt.left;
Top: = prompt.top + prompt.height + 5;
Width: = MulDiv (164, dialogunits.x, 4);
MaxLength: = 255;
Text: = Value;
If Text = ' Password ' then//if the default string passed in is "Password"
PasswordChar: = ' * '; That changes the input box to an asterisk-style
SelectAll;
End
Buttontop: = edit.top + edit.height + 15;
Buttonwidth: = MulDiv (M, dialogunits.x, 4);
Buttonheight: = MulDiv (Dialogunits.y, 8);
With Tbutton.create (Form) do
Begin
Parent: = Form;
Caption: = ' OK '; OK button, the original title is "OK"
Modalresult: = Mrok;
Default: = True;
SetBounds (MulDiv, Dialogunits.x, 4), Buttontop, Buttonwidth,
Buttonheight);
End
With Tbutton.create (Form) do
Begin
Parent: = Form;
Caption: = ' Cancel '; Cancel button, originally titled "Cancel"
Modalresult: = Mrcancel;
Cancel: = True;
SetBounds (MulDiv, Dialogunits.x, 4), Edit.top + edit.height + 15,
Buttonwidth, Buttonheight);
Form.clientheight: = top + Height + 13;
End
If ShowModal = Mrok Then
Begin
Value: = Edit.text;
Result: = True;
End
Finally
Form.free;
End
End
Save the file after the modification is complete.
3. In the current project to add just modified Dialogs.pas, the specific operation: Project-->add to project--> find the file, add in.
4. Set the engineering option:project-->options-->packages--> to cancel build with runtime Packages front of the hook, OK.
5. Add code that uses the InputBox or Inputquery function in your program. Here is an example:
//---------------------------------------------------------------------------
by Ccrun (old Demon) (www.ccrun.com)
The normal Input dialog box effect
void __fastcall Tform1::button1click (tobject *sender)
{
String strtemp = "";
Inputquery ("title", "Hint", strtemp);
ShowMessage (strtemp);
}
//---------------------------------------------------------------------------
The input dialog box effect of the asterisk password, unlike the code above, sets the default string to password
You can implement the asterisk password. This is done to prevent all input dialog boxes from becoming asterisks.
The "Password" here should correspond to the characters in the Dialogs.pas that you just modified.
void __fastcall Tform1::button2click (tobject *sender)
{
String strtemp = "Password";
Inputquery ("title", "Hint", strtemp);
ShowMessage (strtemp);
}

6. Compile the project and run it. You can see the Chinese button, the Asterisk Password Input dialog box.

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.