What is the difference between bool and boolean in delphi programming?

Source: Internet
Author: User

Bool is of the longbool type.

 

Delphi defines four Boolean types: Boolean, bytebool, wordbool, and longbool. The following three Boolean types are introduced for compatibility with other languages. We recommend that you use the boolean type.

The memory usage of these four types of Boolean values is as follows:

Boolean 1 byte

Bytebool 1 byte

Wordbool 2 bytes (1 word)

Longbool 4 bytes (2 words)

For bytebool, wordbool, and longbool, the values of true constants are non-zero and false is zero. You can use the Ord function for verification;

For boolean type, the value of true constant is 1, and false is zero. In the context of the expected Boolean value, the compiler converts the non-zero values of bytebool, wordbool, and longbool to true.

However, in Delphi, Boolean expressions are incompatible with integer/real. The following table compares 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 abnormal.

Booltostr (false) = 0

 

ByteBool, WordBool, LongBool

False <> True

Ord (False) = 0

Ord (True) <> 0

Succ (False) = True

Pred (False) = True

 

BoolToStr is the most inexplicable function. It clearly states that the value of True is 1, but it tells us that True is-1. The original form of the function is:

Function BoolToStr (B: Boolean; UseBoolStrs: Boolean = False): string;

The following table lists the function conversion rules:

B UseBoolStrs Value of returned string

True False '-1'

True TrueBoolStrs array's first value (default, 'true ')

False '0'

False True FalseBoolStrs array's first value (default, 'false ')

 

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.