Tdays= (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
You can define variables of the above enumerated types:
defined variable
day ofweek:t days;
In an enumeration, each value in parentheses has an integer value determined by the location where it is described. For example, Sunday's integer value is 0, Monday's integer value is 1, and so on. You can describe DayOfWeek as an integer variable, and give each talent an integer value in a week, which can achieve the same effect, but using enumeration will make the program more readable and easier to write. When you list a value in the enumeration, it also indicates that the value is an identifier. For example, if your program already contains the TDays type and describes the DayOfWeeks variable, the Monday variable cannot be used in the program because it has been described as an identifier. A subboundary is a series of values: integer, Boolean, character or enumeration. Subboundaries are very useful when you want to limit the range of a variable.
type
Thours=0..23;
TValidLetter='A '..f’;
TDays= (Sunday, Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday); {Enumeration type}
TWorkDay = Monday .. Friday; {child binding of type tdays}
The subboundary defines the possible range of variable values. When range checking is turned on (word {$R*. DFM} indicates that range checking is turned on after the library unit is implemented; otherwise, range checking can be turned on in Options | Project | Component Options); if the variable value is outside subbound, a range checking error will occur. An array is an ordered combination of some data types, in which the value of each element is specified by its relative position. You can put data somewhere in the array and use it when needed. The following types describe array variables of type Double:
defined variable
Check: array [1..Double's10];
It means that Check points to a data string containing 10 Double elements, and each element is represented by a number between 1 and 10, which is called an index. Each item of the array is represented by the array name plus the index in []. Check contains 10 variables, and Check[ 1] represents the first variable. You can also define arrays as types:
type
TCheck=array[ 1..Double10];
Variable description changed to:
defined variable
check:t check;
You can use them by assigning values to arrays. The following statement assigns 0.0 to all elements in the check array:
ForJ:= 1 to 10do
check[J]:= 0.0; ,
Arrays can also be multidimensional. The following types define an array of 20 rows and 20 columns.
type
Ttable=array[ 1..20, 1..20]of double;
defined variable
table 1:TT able;
,; ,; To initialize all the data in this table to 0.0, you can use the for loop:
defined variable
Col, Row: integer;
…
For col:= 1 to 20do
For row:= 1 to 20do
Table 1[Col,Row]:= 0.0; The string type is actually a one-dimensional character array. When describing string variables, you should indicate the size of the string. The following is an example of a string type:
type
MyString:string[ 15];
defined variable
my name:MyString;
The variable MyName is declared to contain at most 15 characters. If you don't specify the size of the string, Delphi will think that the string contains at most 255 characters. You can use single quotation marks to assign values directly to strings:
My name is =' Frank. Smith';
Or MyName:=' Zhang Ming';
Because MyName is a MyString variable that can contain 15 characters, the above two variables are both valid, and a Chinese character can be regarded as two characters. For example, when you assign more values to a string variable than defined, please assign MyName to FrankSmith. Franklin'', Delphi only accepts the first 15 characters'' FrankSmith. Fran. In memory, a string usually takes up one byte more than the specified size, because the first position is the byte containing the size of the array. You can use the index value to access the characters of the string, and MyName[ 1] can get the first character' f' of MyName.
You can use Delphi's rich operators, procedures and functions to handle string variables and attributes. Here are some commonly used operators and Delphi programs or functions:
Concat and (+) have the same function. They can combine multiple strings to create a larger string. Copy will return substrings in the string; Delete deletes a certain number of characters from the specified position in the string; Insert inserts a string into a string; Length returns the length of the string; Pos returns the position of the substring in the string, that is, the index value. A collection type is a group of elements of the same type, which must be of finite types, such as integer, Boolean, character, enumeration and subboundary. Collection types are useful when checking whether a value belongs to a specific collection. The following routine can illustrate the usage of the collection type: add an edit box and a button to the form, clear the text in the edit box, add a label titled "Input vowel", add an empty label under the edit box, and change the default property of the button to True. The event handling process of creating a button is as follows:
procedureTForm 1。 Button 1Click (sender: toobject);
type
Tvowels = setofChar
defined variable
Vowel: TVowels
begin
Vowels: =['a',' e',' i',' o',' u'];
ifEdit 1。 The text [1] is involved.
Label2.caption: =' is a vowel';
other
Label2.caption: =' Please try again';
End;
Execute the program and enter letters in the edit box. The result of the expression Edit 1 Text [1] Invoices is Boolean, and in is the operator to judge whether there are letters in the collection. The input authentication result will be displayed at the bottom of the edit box. The collection type TVowels is used above. A record is a collection of data that your program can access in groups. The following routine illustrates the usage of the record type:
type
TEmployee = record
Name: string [20];
Recruitment year:1990 ... 2000;
sals ry:Double;
position:string[20];
End;
Records contain fields that can store data, and each field has a data type. The above record TEmployee type contains four fields. You can interpret record variables in the following ways:
defined variable
NewEmployee,promoted employee:TEmployee;
You can access a single record field in the following ways:
New employee. Salary: =1000;
You can assign a value to the whole record by writing the following statement:
withPromotedEmployeedo
let’s begin
Name: ='';
year hired:= 1993;
Salary: =2000.00.
position:= ' editor ';
End;
Your program can manipulate records as a single entity:
prompt employee:= new employee;
The user-defined types commonly used are described above. In Delphi programming, object is a very important user-defined data type. Like a record, an object is a structured data type, which contains data fields and procedures and functions as methods. In Delphi, when you add a widget to a form, you add a field to the form object; Each part is also an object. Whenever you set up an event handler so that a part can respond to an event, you automatically add a method to the form.