Re: Question about Delphi versus other languages

From: VBDis (vbdis_at_aol.com)
Date: 10/18/04


Date: 18 Oct 2004 15:24:37 GMT

Im Artikel <BaCcd.2533$rh1.72183@news2.e.nsc.no>, "Sven Pran"
<no.direct@mail.please> schreibt:

>And please remember that the internal data format for boolean variables
>implemented in byte, word or longword fields defines the available values:
>
>0 as false and any nonzero value as true.

Please note that these types are different from the predefined "Boolean" type.
The Boolean and ByteBool as well as the Char type happen to be stored in bytes,
but nonetheless they are very distinct data types.

>This means that ordinal values greater than one are not undefined nor
>are they illegal. They are just "true" (all of them).

This is true when such almost-boolean values must be converted into an Boolean
value. Unfortunately Borland decided that such values are converted silently
into boolean whenever required, causing your confusion about the really-Boolean
and almost-boolean types.

An implicit conversion of almost-boolean types can occur in boolean
expressions:
  if x then
but a comparison
  if x = y then
compares the ordinal values of the almost-boolean types, without converting
them into Boolean before.

I'd treat WordBool etc. just like Variant, i.e. types that can show an
unexpected behaviour. Use them at your own risk!

Another source of confusion are the logical operators, that can work bitwise as
well as logical. Other languages have different operators for these different
purposes, like "&" and "&&" in C. Unless both operands are really Boolean, the
Delphi logical operators work bitwise, not logical!

DoDi



Relevant Pages

  • Re: Form k = i + j and test for overflow.
    ... and declare it as anything _other_ than integer in Fortran, ... C itself has no boolean data type, but it has entities that require ... C programmers are encouraged to use any int as a boolean ... the logical operators do the right thing, ...
    (comp.lang.fortran)
  • Re: Code not producing desired result.
    ... | and & aren't logical operators on int types, ... applied to boolean operands. ... ^) may be applied to numeric or boolean operands. ... it is clear that the Conditional operators ...
    (comp.lang.java.programmer)
  • Re: returning values from multiselect list as string
    ... > calculation, including boolean arithmetic. ... The conversion of *both* ... The most common boolean expressions used in If-Then statements use the ... and some languages give assignment and comparison ...
    (microsoft.public.word.vba.beginners)
  • FormView checkbox two-way bind problem with null fields
    ... In the source these fields my be empty. ... Conversion from type 'DBNull' to type 'Boolean' is not valid. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: True = -1 ?
    ... >> is to wrap the boolean with Absto force it to output a 1 instead ... > Because VB does not have logical operators, only binary operators. ... > In a language with both logical and binary operators, like C, there are ...
    (microsoft.public.vb.general.discussion)