Autor Beitrag
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mo 05.04.04 21:26 
Motzi, das musste mir mal genauer erklären!

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 05.04.04 22:04 
Im Prinzip ganz einfach...

Ein Boolean ist eigentlich nichts anderes als eine Menge:
ausblenden Delphi-Quelltext
1:
2:
type
  Boolean = (False, True);

Solche Mengen sind intern aber eigentlich nichts anderes als Zahlen.. jeder Wert der Menge entspricht einer Zahl (von 0 angefangen). Daher entspricht 0 dem Wert False und 1 dem Wert True.

Bei einem Vergleich mit True wird also praktisch mit dem Wert 1 verglichen. Im anderen Fall wird alles ungleich 0 als True betrachtet.
Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  i: Integer;
begin
  i := 2;
  if Boolean(i) then
    ShowMessage('Boolean(' + IntToStr(i) + ') => True')
  else
    ShowMessage('Boolean(' + IntToStr(i) + ') => False');

  if Boolean(i) = true then
    ShowMessage('Boolean(' + IntToStr(i) + ') = true => True')
  else
    ShowMessage('Boolean(' + IntToStr(i) + ') = true => False');


PS: den Beweis für True=1 bzw False=0 kannst du dir auch holen wenn du dir man das Ergebnis des Aufrufs von Ord(True) bzw Ord(False) anschaust...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!