(ZT) a programmer's development habits

xiaoxiao2021-03-06  49

A programmer's development habits (ZT)

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. Establishing a project catalog First, the first step is to do, of course, 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 directories in this directory: : Used to store the project related development document (required instructions, profile design, detailed design, etc.); : used to store Delphi source programs ".Dpr", ". PAS", ". Dfm" and other files; : The ".dcu" file is stored in this directory, and the '.pas' and '.dcu' file are stored simply in order to let the Source directory The content is more clear; : 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. Setting up engineering options Create a new project in Delphi, save this project into the Source directory, while: a. Choose a lookable, icon in contact with the project as the icon of 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 to add a new unit, saved as "Unt Consts.PAS" to save the constant used in the project.

four. The form (FORM) and Unit (Unit) are named after the Hungarian nomenclature, and a form for logging in can be named 'frmlogin', and its cell name can be 'unstlogin'. 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 at CAPTION when TForm.onCreate event is triggered, such as Procedure TFRMLogin.formCreate (Sender: TOBJECT); begin caption: = cslogintitle; .... End; 5. About the Format function has three data in Iyear, IMONTH, IDAY, what you usually do, 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. Regarding the Storage of the Registry or INI file Original Access Registry I usually use Tregistry, and access the INI file usually use 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. For example: var csmIniFile: TCusomIniFile; begin if blUseIniFile then // If Ini File csmIniFile: = TIniFile.Create (csRootKey) else csmIniFile: = TRegistryIniFile.Create (csRootKey); // csmIniFile then can be used to access files Ini, / / Access the registry with a similar access to the INI file. Seven. About TSTREAM streams 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 a Function Save (ASTREAM: TSTREAM): Boolean; it is more flexible than defining function save (astream: tfilestream): Boolean; 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 TACTION Delphi 4 to introduce 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!

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

New Post(0)