Development habits of a Delphi programmer (non-technical issues)

zhaozj2021-02-11  162

Development habits of a Delphi programmer (non-technical issues)

Author: Musicwind®

Create time: 2001-09-26

~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~

Some ideas about development habits, such as being in the throat, not spitting. The motivation will certainly do not exclude the possibility of defrauding participation, but on the other hand, I hope to provide some suggestions for the peers (the XING), or reference (hope is not a misunderstanding). At the same time, I hope that you can publish a point of view of my bad habits, and give criticism and adequate views. Thank you.

One. Establish an engineering catalog

First of all, the first step is to do, of course, to build a separate directory (don't laugh) for the new project. The directory name is the same name with the project name, or can be taken one, as long as it is clear, concise. Then create the following directorys in this directory:

: Used to store the project related development document (required instructions, summary design, detailed design, etc.);

: ".dpr", "PAS", ". DFM" and other files used to store Delphi source;

: The ".dcu" file is stored in this directory, and the '.pas' and '.dcu' file are stored simply in order to make the Source directory more clearly;

: Storage project output file, such as ".exe", "DLL" or ".ocx", etc.

: Used to store log files; usually in this directory I will put a " programmer log .txt" file.

: of course is the directory of the picture used in the storage project. In general, this directory is less. If other resources are used, they are also established, such as WAV, such as AVI, and more.

two. Set the project option

Create a new project in Delphi, save this project into the Source directory, while:

a. Choose an icon for this project as an icon for this project. Of course, this icon may be just temporary use, but it is always better than Delphi's default. Otherwise, how can you get yourself?

b. Set the Output Directory in the Project Options -> Directories / Conditionals page to bin directory;

c. Set the Unit Output Directory as the DCU directory.

three. Add a constant unit

Add a new Unit, saved as "Unt Consts.PAS" to save the constant used in the project.

four. About Forms (FORM) and Unit (Unit)

According to the Hungarian nomenclature, give the form, a form used to log in can be named 'frmlogin', and its cell name can be 'unlogin'. Typically, the names of the two corresponding FORMs and Unit should be consistent after removing the abbreviation of 'FRM' or 'Unt'.

Adding this unit's annotation, the format of the comment can be referred to the source code of Delphi, but at least the following items should be included: function description; author; copyright; create time; final modification time; modification history, etc.. Set the newly created Form's CAPTION to the name of the Form class, instead of using Delphi default. For example, after the Form1 is renamed frmlogin, we got TFRMLogin's new form class, and Delphi automatically updated the CAPTION 'of' frmlogin '. According to me, the CAPTION should be 'tfrmlogin' is because we are designing a form TFRMLOGIN instead of only FRMLogin.

Many people have a habit of setting their CAPTION as the name of "operator login" in the design period. My habit is that constants such as "operator login" are usually stored in the UN Consts.PAS, defined by resourceString, or using const. As for the naming of the form's CAPTION, it should be a running period. So, I often operate CAPTION when TForm.onCreate event is triggered, such as:

Procedure tfrmlogin.formcreate (sender: TOBJECT);

Begin

Caption: = CSLogintitle;

....

END;

Fives. Using the Format function

There are three data in Iyear, IMONTH, IDAY, to show information such as "birthday: 1976/3/18", what do you usually do? Use s: = 'birthday:' INTOSTR (IYEAR) '.' INTOSTR (iDAY);? This is really too tired. My habit is to add a constant csbirthDayformat = 'birthday:% D /% D /% d' to save the display format in the UN Consts.PAS, then use S: ​​= Format, [Iyear, IMOMONTH , iDay]); This statement completes the assembly of data. The benefits of doing this are obvious, that is, you only need to maintain data in a local maintenance display format.

The Format function is powerful, I am very respect for it, what about you?

six. Storage about registry or INI file

I originally accessed the Registry I usually use Tregistry, and the access INI file usually uses TiniFile. The use of these two classes is different, so it is almost impossible to use the same code to access the registry and access the INI file. Really hurt!

I finally found the savior! That is the TregiStryiniFile class. View the Registry unit, we found that TregistryInifile inherits from TcusominiFile. TiniFile is also inherited in TcusominiFile. Therefore, using abstract class TCUSominiFile to achieve access to the registry or INI file is two. such as:

VAR

CSMINIFILE: TCUSominifile;

Begin

If bluSeinifile the// If INI file is used

CSMINIFILE: = TiniFile.create (CSRootKey)

Else

CSMINIFILE: = TregiStryiniFile.create (CSROOTKEY); / / You can access the INI file using CSMINIFILE.

/ / Access the registry with a similar access to the INI file.

Seven. About TSTREAM stream and TFileStream, TmemoryStream, etc.

TFileStream and TMemoryStream are inherited from abstract class TSTREAM, which means we can use a set of code to complete access to files and memory. Therefore, when some interfaces are defined, I tend to define the type of parameters as an abstract class, not a specific class. For example, to complete a function of the save function, define

Function Save (ASTREAM: TSTREAM): Boolean;

Comparison

Function Save (ASTREAM: TFileStream): Boolean;

To be more flexible.

The previous definition is forward-looking because it can be applied to the flow of new types that may occur later. The latter definition only applies to TFileStream this stream (of course, including TFileStream's subclasses), and more.

My habits: If there is an abstract class, try to define the parameters as the type of abstract class. After all, we cannot foresee the future.

Eight. Use more TACTION

Delphi 4 introduces the concept of Action, and add TACTIONLIST components in the Standard component column. The benefits of using Action is that the troubles of the status synchronization of the control status are swept away!

More articles

MusicWind®@hangzhou.zj.china

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

New Post(0)