The integer _ floating point number _ character _ string in Delphi's series _ 2_delphi

Source: Internet
Author: User

After two or three days of study, I found that Delphi has many data types and is flexible. Especially strings and characters

Type. At the same time, it is found that there are some special data types in Delphi, such as set. This is interesting and can be input and combined.


Program datastruct; {$ apptype console} {Various data types in this project/project are used to test D7} uses sysutils; Type // istruct = record ishortint: integer int; // 8-bit signed integer ibyte: byte; // 8-bit unsigned integer ismallint: smallint; // 16-bit signed integer iword: word; // 16-bit unsigned integer iinteger: integer; // 32-bit signed integer ilongint: longint; // 32-bit signed integer icardinal: Cardinal; // 32-bit unsigned integer ilongword: longword; // 32-bit unsigned integer iint64: int64; // 64-bit signed integer end; // floating point number record freal = record fsingle: single; // 4 bytes Floating Point freal48: real48; // 6-byte floating point fdouble: Double; // 8-byte floating point fextended: extended; // 10-byte floating point fcurrency: currency; // 64-bit currency value end; // string record strstruct = record strshortstring: bytes string; // string stransistring: ansistring; // dynamic string strpchar: pchar; // string strwpchar ended with NULL: pwidechar; // The wide string strwide: widestring ended with NULL; // The dynamic wide string end; // character type record charstruct = record bytechar: Char; wodechar: widechar; end; vaR myvar1: istruct; Myvar2: freal; myvar3: strstruct; myvar4: charstruct; STR: String [100]; begin {todo-ouser-cconsole main: insert code here} {8-bit signed integer if a value less than-128 is assigned to myvar1.ishortint, a compilation error is returned. If a value greater than 127 is assigned to myvar1.ishortint, a compilation error is returned.} myvar1.ishortint: = 127; {8-bit unsigned integer if a value greater than 255 is assigned to myvar1.ibyte, an error is returned. If a value less than 0 is assigned to myvar1.ibyte, an error is returned.} myvar1.ibyte: = 255; writeln (myvar1.ibyte); {a 16-bit signed integer is assigned to myvar1.ismalli if it is a value smaller than-32768 or greater than 32767. If NT is compiled, an error is returned.} myvar1.ismallint: = 32767; {16-bit unsigned integer. If a value smaller than 0 is assigned to mayvar1.iword, a compilation error is returned. If a value greater than 65535 is assigned to myvar1.iword, compilation error} myvar1.iword: = 65535; {32-bit signed integer value is relatively large, usually 32-bit signed integer can meet the general application,} myvar1.iinteger: = 39939339; myvar1.iinteger: = myvar1.iinteger * (-1); myvar1.ilongint: = myvar1.iinteger; {32 unsigned integer value is also large, which can usually meet general requirements} myvar1.icardinal: = 890879789; myvar1.ilongword: = myvar1.iinteger; {64-bit signed integer is not provided in Object Pascal The 64-bit unsigned integer type has a larger data range. We recommend that you do not use this type of data if the value is not large.} myvar1.iint64: = 893802830283209; {after the data variable is defined, the 4-byte floating point occupies 4 bytes of memory space. This is the sigle type of data, that is, the single-precision data type, the instance shows that the precision of a single precision is 6 digits after the decimal point} myvar2.fsingle: = 3.93998777888; writeln (myvar2.fsingle ); {6-byte floating point number real48 data is retained to be compatible with earlier versions of Delphi. Therefore, we will not introduce it.} {8-byte floating point number is double-precision floating point number, if an 8-byte floating point exists, you can see that the precision of the double-precision floating point number is 13 digits after the decimal point} myvar2.fdouble: = 3.141592678934545876; writeln (myvar2.fdouble); {10-byte floating point number That is, the Extended Floating Point number occupies 10 bytes in the memory. The instance shows that the precision of the Extended Floating Point Number is 14 digits after the decimal point} myvar2.fextended: = 3.12345678910111213; writeln (myvar2.fextended ); {8-byte currency-type floating point number is a currency-type floating point number. If you use 8 bytes in the memory, you can know that the precision of the currency-type floating point number is 4 digits after the decimal point} myvar2.fcurrency: = 3.123456789101112; writeln (myvar2.fcurrency); {the fixed length is the fixed length defined by the string in Object Pascal. The string type is 'string'. The data type can contain up to 255 characters. In addition, the string type can be referenced like the array type} myvar3.str1_string: = 'abcd'; // here we need to note that, in the bytes allocated for shotstring, // The first byte of the string is the length of the string. If myvar3.strshortstring [0] = #4 then writeln ('the length of myvar3.strshortstring "', myvar3.strshortstring,'" is: ', length (myvar3.strshortstring )); {dynamic strings are relatively flexible. Keyword: string can be used to define string variables (objects should be accurate). But there is a problem here. If there are so many string types, what is the default definition type of string? After the D2 environment, the object defined by string is defined as ansistring by default. You can use the compilation switch/option to correct this default option} // enable the compilation option {$ H-} // The string defined by string is of the sort sting type {$ H ++} // string definition. the string is ansistring {after the H + option is enabled, there is an exception, that is, when the length of a string is specified, the string type of 'str' is as follows: 'str' is a string object of the length of 100 bytes 'str': String [100, let's test its length} // The output result of the following statement is 101, which means that the system will add a byte indicating its length to the string by default. // It can also be verified, the exception of the H + Option writeln ('the length of STR is: ', sizeof (STR); {the string ending with null can be known by this title, the default string terminator of optional string and ansistring types is not null, but can Is another character, which is the difference between it and the length of a character such as "ABCD" in C language. To be compatible with Win32 API functions, D has a built-in string type pchar ending with null.} // Exp: the following example shows that sizeof does not calculate the space occupied by #0 when determining the length of a pchar string. // You can also know that pchar will automatically add null characters at the end when processing the string/ /You can also know that 'abcd' occupies 4 bytes of space. Myvar3.strpchar: = 'abcd'; If (myvar3.strpchar [4] = #0) and (myvar3.strpchar [0] = 'A') Then writeln ('the length of myvar3.strpchar is :', sizeof (myvar3.strpchar); {single-byte characters are the same as those in C. You can use either of the following methods, 'A', a constant notation, or a representation like #13, we can know that a = #61 doesn't know how a single character is represented in Delphi. I hope that man can explain it?} Myvar4.bytechar: = #61; If myvar4.bytechar = 'A' then writeln ('the myvar4.byte is: ', #61); readln (myvar3.stransistring); end.

There are several other minor issues that have not been solved:

1. How to express the characters in Delphi? I tested them in a format like 'A' and found that they are not compatible with #61. 61 is the ASCII value of.

2. # Does This indicate a single character? After my previous two days of study and tests over the past few days, I found that this is the same as \ 061 in C.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.