Usually we write Delphi constants are directly defined in the use of cell files, a bit of programming habits may be used to put the system constants in a separate file, but also similar to the following way:
Const
Default_user_name = ' ADMIN ';
Default_user_type_code = 0;
Accustomed to Java, it is customary to divide different constants into different classes. This makes it easy to separate system constants, user constants, database constants, and so on. So in Delphi also want to reference a constant unit, and then in the button event and so on inside this use:
Edit1.text: = Constants.default_user_name;
Spinedit1.value: = Constants.default_user_type_code;
But it's hard to find such information on the web, so find out for yourself. It is found that using the structure const can achieve this effect, written as follows:
Unit unitconstants;
Interface
Uses
Classes, Types;
Type
Constantrecord = Packed record
default_user_name:string;
Default_user_type_code:integer;
End
Const
Constants:constantrecord = (
Default_user_name: ' ADMIN ';
default_user_type_code:0
);
Implementation
End.
Then in the quoted unit, you can use Constants.default_user_name and constants.default_user_type_code to facilitate