Create a Delphi form template

Source: Internet
Author: User

The form must implement the following functions:

<! -- [If! Supportlists] --> 1.
<! -- [Endif] --> This form is used as an MDI sub-form. By default, the MDI sub-form of Delphi is minimized. Therefore, you need to modify it to completely release the form. <! -- [If! Supportlists] --> 2.
<! -- [Endif] --> Chinese display environment. <! -- [If! Supportlists] --> 3.
<! -- [Endif] --> enter, instead of the tab key, enables control switching. <! -- [If! Supportlists] --> 4.
<! -- [Endif] --> displays the status of the main data source on the form after the Form title because the information management system has a data module, therefore, you need to add a data source control (tdatesource) on the form to implement this function. <! -- [If! Supportlists] --> 5.
<! -- [Endif] --> only the data sensing control that is connected to the data source when the dataset is in the Add/edit status is available. Other statuses are unavailable. This function is implemented by changeenabletrue; and changeenablefalse. When using this function, you only need to set the tag value of the control to 86, so that the two functions can control the specific implementation method as follows: First, create a new form in the project and name it fmexample, place a tag control and a datesoure control on the form. Fmexample:
Attribute name Value Note
Caption Form template  
Hint This is a demo form! It can be displayed in the status bar of the main form in the activation event.
Formstyle Fsmidchind As a mid subform
Positin Pomainformcenter Center the main form
Borderstyle Bssingle Border Style
Font-> charset Gb2312_charset Character Set Encoding
Font-> name Character Set Name
Font-> size 9 Font Size
Keypreview True Key event
Tdatesource:
Attribute name Value Note
Name Stateds  
Tlable:
Attribute name Value Note
Name Frmcaptionlab  
Caption Input window title  
The form unit file is as follows: {*************************************** ************************************}

Software producer: stosc

Contact: E-mail: endlock@gmail.com

Copyright (c) 2007 violation of copyright law

{*************************************** * **********************************} Unit uexample; interface uses

Windows, messages, sysutils, variants, classes, graphics, controls, forms,

Dialogs, DB, dbclient, stdctrls, dbctrls, mask, UDM, grids, dbgrids, comctrls,

Buttons; Type tfmexample = Class (tform) stateds: tdatasource; frmcaptionlab: tlabel; dbgrid2: TDBGrid; Procedure formcreate (Sender: tobject );

Procedure dbcombobox1enter (Sender: tobject );

Procedure combobox1enter (Sender: tobject );

Procedure formkeypress (Sender: tobject; var key: Char );

Procedure statedsstatechange (Sender: tobject );

Procedure formclose (Sender: tobject; var action: tcloseaction );

Procedure formactivate (Sender: tobject); function changeenabletrue: variant; // set the tag = 86 control to the available function changeenablefalse: variant; // set the tag = 86 control to private {private Declarations} public {public declarations} end; var fmexample: tfmexample; implementationuses usellmain; {$ R *. DFM}

Procedure tfmexample. formclose (Sender: tobject; var action: tcloseaction );

Begin // close the form and release the memory action: = cafree; // clear the status bar to display usellmain. mainfm. statusbar1.panels. items [1]. Text: = ''; end;

Procedure tfmexample. formcreate (Sender: tobject );

Begin end;

Procedure tfmexample. formkeypress (Sender: tobject; var key: Char );

// Use the Enter key in the form instead of the tab key to switch beginif key = #13 then // determine whether the press enter and press the execution key if not (activecontrol is TDBGrid) then // not in the TDBGrid control begin key: = #0; perform (wm_nextdlgctl, 0, 0); // move to the next control end else if (activecontrol is TDBGrid) then // is begin the TDBGrid control with TDBGrid (activecontrol) do if selectedindex <(FieldCount-1) Then selectedindex: = selectedindex + 1 // move to the next field else selectedindex: = 0; end; end;

Procedure tfmexample. statedsstatechange (Sender: tobject); // display the dataset status

VaR sdatestate: string;

Begin case stateds. state of dsinactive: Begin sdatestate: = 'inactive'; self. changeenablefalse; end; dsbrowse: Begin sdatestate: = 'browsed '; self. changeenablefalse; end; dsedit: Begin sdatestate: = 'modify'; self. changeenabletrue; end; dsinsert: Begin sdatestate: = 'add New Record '; self. changeenabletrue; end else begin sdatestate: = 'other status'; self. changeenablefalse; end; self. caption: = frmcaptionlab. caption + '--' + sdatestate; end;

Procedure tfmexample. formactivate (Sender: tobject );

Begin // display the prompt information on the status bar usellmain. mainfm. statusbar1.panels. items [1]. Text: = self. Hint; end;

Function tfmexample. changeenabletrue: variant; // set the tag = 86 control to available

VaR I: integer; begin for I: = 0 to ControlCount-1 do begin

If controls [I]. Tag = 86 then controls [I]. Enabled: = true;

End; end;

Function tfmexample. changeenablefalse: variant; // set the tag = 86 control to unavailable.

VaR I: integer; begin for I: = 0 to ControlCount-1 do begin

If controls [I]. Tag = 86 then controls [I]. Enabled: = false;

End; end.

When using the template, go to flie-> New-> other and find the template form (Delphi7 is in inheritable items in the tab with the same name as the project ), the created form inherits the features of the form. All child forms inherited from this form will be modified as long as this template form is modified in the future.

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.