Types Defined Differently

From Appmethod Topics
Jump to: navigation, search

Go Up to Language Support for the Appmethod Libraries (C++)


Types that are defined differently in Object Pascal and C++ are not normally cause for concern. The rare cases in which they are problematic may be subtle. For this reason, these types are mentioned in this section.

Boolean data types

The True value for the Object Pascal ByteBool, WordBool, and LongBool data types is represented in Object Pascal as –1. False is represented as 0.

Note: The Boolean data type remains unchanged (True = 1, False = 0).

While the C++ bool type converts these Object Pascal types correctly, there is a problem when sharing a WinAPI function or any other function that uses a Window’s BOOL type, which is represented as 1. If a value is passed to a parameter of type BOOL, it evaluates to –1 in Object Pascal and to 1 in C++. Therefore, if you are sharing code between these two languages, any comparison of the two identifiers may fail unless they are both 0 ( False, false). As a workaround, you can use the following method of comparison:

 !A == !B;

The following table shows the results of using this method of equality comparison:

Equality comparison !A == !B of BOOL variables

Object Pascal C++ !A == !B

0 (False)

0 (false)

!0 == !0 (TRUE)

0 (False)

1 (true)

!0 == !1 (FALSE)

-1 (True)

0 (false)

!-1 == !0 (FALSE)

-1 (True)

1 (true)

!-1 == !1 (TRUE)


With this method of comparison, any set of values will evaluate correctly.

Char data types

The char type in C++ is a signed type, whereas it is an unsigned type in Object Pascal. It is extremely rare that a situation would occur in which this difference would be a problem when sharing code.

See Also