Delphi defines four types of Booleans: Boolean,bytebool,wordbool and Longbool. The following three types of Booleans are introduced for compatibility with other languages

Source: Internet
Author: User
Tags ord true true

BOOL is the Longbool type.

Delphi defines four types of Booleans: Boolean,bytebool,wordbool and Longbool. The following three types of Booleans are introduced for compatibility with other languages, and the Boolean type is generally recommended.

The four types of Boolean values that occupy memory are as follows:

Boolean 1 Byte

Bytebool 1 Byte

Wordbool 2 Bytes (1 Word)

Longbool 4 Bytes (2 Words)

For Bytebool,wordbool and Longbool, the value of the three type true constants is nonzero, false is zero, and can be verified with the ORD function;

For Boolean types, the value of the true constant is 1,false zero. In the context where the Boolean value is expected, the compiler converts Bytebool,wordbool and longbool three types of non-0 values to true.

However, Boolean expressions and Integer/real are incompatible in Delphi. The table below contrasts the similarities and differences between Boolean and Bytebool/wordbool/longbool:

Boolean

False < True

Ord (False) = 0

Ord (True) = 1

SUCC (False) = True

Pred (True) = False

Booltostr (True) =-1//This function is perverted.

Booltostr (False) = 0

Bytebool, Wordbool, Longbool

False <> True

Ord (False) = 0

Ord (True) <> 0

SUCC (False) = True

Pred (False) = True

Booltostr This function is the most puzzling, clearly said that the value of true is 1, and it tells us that true is-1. The prototype of the function is:

function Booltostr (B:boolean; Useboolstrs:boolean = False): string;

The following table is the conversion rule for a function:

B useboolstrs Value of returned string

True False '-1 '

True True trueboolstrs the first value of the array (default, ' True ')

False ' 0 '

False True Falseboolstrs The first value of the array (default, ' FALSE ')

http://blog.csdn.net/zisongjia/article/details/72963204

Delphi defines four types of Booleans: Boolean,bytebool,wordbool and Longbool. The following three types of Booleans are introduced for compatibility with other languages

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: info-contact@alibabacloud.com 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.