Delphi programmer code preparation standard guide (5)

zhaozj2021-02-17  54

V. Forms and data templates

5.1 Form

5.1.1 Form Type Name Standard

The name of the form type should be able to express the purpose of using the form. Type definition should be prefix T. The prefix followed by the descriptive name. Finally, a Form suffix should be applied to describe the name. For example, the name of the type of "about" the form should be:

TaboutFrom = Class (TFORM);

The definition of the main form is:

TMAINFORM = Class (TFORM);

The name of a user access the form should be like:

TCUSTOMERENTRYFORM = Class (TFORM);

5.1.2 Form instance naming standard

The form instance should be the name of the corresponding class with a prefix T. For example, the name of the example should be: corresponding to the previous form type.

Type Name Example Name

TaboutForm Aboutform

TMAINFORM Mainform

TCustomerentryform Customerentryform

5.1.3 Automatically create a form

Only the main form can be automatically created unless otherwise better reasons do not do so. All other forms must be removed from the automatic creation list in the Engineering Options dialog box. Check out the following sections to get more information.

5.1.4 Mode Form Instantiation Function

All form units should contain a form instantiation function, which is used to create, set, modely display the form, and release the form. This function should return the pattern of the form. The parameters you want to pass should follow the "Parameter Pass" standard specified by this document. The functionality packaged in this way helps the reuse and maintenance of the code.

The variable of the form is to be removed from the unit, and a local definition is performed in a function of the form. Note that this means that the form must be removed from the automatic creation list in the Project / Options dialog. Refer to "Automatically Create Form" later in this document.

For example, the unit below shows a function in the GetUserData form.

Unit userdatafrm;

Interface

Uses

Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms,

Dialogs, stdctrls;

Type

TuserDataForm = Class (TFORM)

EDTUSERNAME: TEDIT;

EDTUSERID: TEDIT;

Private

{Private Declarations}

public

{Public declarations}

END;

Function GetUserData (VAR AUSERNAME: STRING; VAR AUSERID: Integer:

Word;

IMPLEMENTATION

{$ R * .dfm}

Function GetUserData (VAR AUSERNAME: STRING; VAR AUSERID: Integer:

Word;

VAR

UserDataForm: tuserdataform;

Begin

UserdataForm: = tuserdataform.create (application);

Try

UserDataForm.caption: = 'getting user data';

RESULT: = Userdataform.ShowModal;

IF (result = mrok) THEN

Begin

AUSERNAME: = UserDataForm.edtuserName.Text;

AUSERID: = STRTOINT (UserDataForm.edTUserid.text);

END;

Finally

UserDataForm.Free;

END;

END;

End.

5.2 Data Template 5.2.1 Data Template Naming Standard

The name of the data template should meet the purpose of using the data template. The definition of the type should be prefeded T, followed by the descriptive name, and finally add the debug word "Datamodule". For example, a custom data template is sometimes like:

TCUSTOMERDATAMODULE = Class (TDATAModule)

The name of an ordered data template should be imaged:

TordersDataModule = Class (TDATAModule)

5.2.2 Data Template Instance Name Standard

The name of the data template instance should be the name of the type that does not have a prefix T. For example, for the previous form type, the name of the example should be:

Type Name Example Name

TcustomerDataModule CustomerDataModule

TordersDataModule ORDERSDATAMODULE

Sixth, package

6.1 Comparison of running packages and design packages

The outline of the runtime should only contain the units or components required for other component packages. Additionally, the included attribute / component editor and other code to be designed should be placed in the design timing package. The registration unit should be placed in the design package.

6.2 file naming standard

The name of the package should be followed by:

"Iiilibvv.pkg" - design time package

"Iiistdv.pkg" - running package

Character "III" represents a 3-character identification prefix. This prefix is ​​used to indicate companies, individuals, or other identified entities.

Character "VV" is represented as the version number of the package that you want to correspond to a version of Delphi.

Note that the name of "lib" or "std" in the name of the package is to indicate that this is a design time package or a runtime package.

If it is both a design time package and a runtime package, the name of the file is the same above, for example, the name of the package made for the Delphi 4 Developer Guide should be:

DDGLIB40.PKG - Design Time Package

DDGSTD40.PKG - Running

转载请注明原文地址:https://www.9cbs.com/read-30443.html

New Post(0)