官术网_书友最值得收藏!

  • Expert Delphi
  • Pawe? G?owacki
  • 255字
  • 2021-07-02 20:44:23

Constants

A constant is an identifier that marks a value that cannot change. The normal decimal notation is used for numbers that are integer or real constants. A hexadecimal integer constant uses a dollar sign as a prefix. It is also possible to use the engineering notation, where an exponent follows the E or e character.

A character string is a sequence of zero or more characters written in one line in the program and enclosed within apostrophes. A character string with nothing between the apostrophes is called a null string. Two sequential apostrophes in a character string denote a single apostrophe character.

For example, a string constant would print out as just Pawe?'s computer, as shown in the following program:

const 
  s = 'Pawe?''s computer'; 

Object Pascal allows the use of constant expressions. The compiler evaluates them at compile time without actually executing the program.

Object Pascal makes it possible to embed control characters in character strings. The # character followed by an unsigned integer in the range of 0 to 255 means a character of the corresponding ASCII value. A useful example of this capability is embedding a newline character in a string constant, so it is displayed in multiple lines. For example, check out the following code snippet:

const EL = #13; 
 
procedure TForm1.ButtonMultilineClick(Sender: TObject); 
begin 
  ShowMessage('Welcome!' + EL + 'Good morning!'); 
end; 

Embedding the new ASCII 13 newline control character displays the message in two lines. For readability, the actual newline character is defined as a constant.

主站蜘蛛池模板: 玛纳斯县| 奉节县| 扶绥县| 牙克石市| 乌审旗| 南雄市| 榆林市| 城市| 鄂温| 四会市| 镇赉县| 宁远县| 楚雄市| 福海县| 正宁县| 寿光市| 呼伦贝尔市| 家居| 托克托县| 民勤县| 秦皇岛市| 上犹县| 江永县| 永顺县| 丽水市| 五大连池市| 白水县| 双桥区| 延吉市| 北京市| 德阳市| 乌拉特前旗| 朝阳区| 永嘉县| 鄄城县| 鄱阳县| 黔江区| 岑溪市| 大化| 张家口市| 广灵县|