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 a project catalog?? 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:????
: Use to store the project related development document (required description, summary design, detailed design, etc.);
????
: Use files such as ".dpr", "pAS", ". Dfm" in the Delphi source program;
????
: The ".dcu" file is stored in this directory, and the '.pas' and '.dcu' file are stored simply 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 "
????
: Of course, it 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 with a part of the 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 a DCU directory.
three. Add a constant unit
?? Add a new unit, saved as "Unt
four. About Forms (FORM) and 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
Procedure tfrmlogin.formcreate (sender: TOBJECT);
Begin
????? Caption: = cslogintitle;
??? ....
END;
Fives. Using the Format function
?? There are three data of Iyear, IMONTH, IDAY, to display 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
??? 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 you use an Ini file?
?? csminifile: = TiniFile.create (CSRootKey)
? Else
?? csminifile: = TregiStryiniFile.create (CSRootKey);
? // Next, you can use CSMINIFILE to access the INI file.
/ / 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!