Autor Beitrag
Zuckerrübe
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Sa 28.03.09 11:56 
Hey,

wie kann ich in einer if Function mehrere Bedingungen mit AND und OR mit einander Verknüpfen ??

z.B.

ausblenden Delphi-Quelltext
1:
2:
if (a=2and (b>1then
  c:= 50;


schlechtes Beispiel aber vielleicht versteht einer was ich mein. ;-)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 28.03.09 11:59 
Äh, genau so, wie du es gerade gepostet hast :lol:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 28.03.09 12:01 
Hi :)

Eigentlich sagt dein Beispiel ja schon alles :gruebel:
ausblenden Mal ein etwas komplexeres:
1:
if a and not ((b or c) and (d or e))					


<=>Wenn a wahr ist, aber gleichzeitig b, c, d und e falsch sind.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Zuckerrübe Threadstarter
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Sa 28.03.09 12:19 
Danke für eure schnellen Antworten, aber dein Beispiel ist echt komplex ^^

also ich habe folgendes Problem:

ich will schaun ob in 3 panels das gleiche drin steht und wenn ja dann soll er in ein label was einfügen.

ausblenden Delphi-Quelltext
1:
2:
if (Panel1.Caption) and (Panel2.Caption) and (Panel3.Caption) = 'X' then
  label1.Caption:= 'was weis ich ^^';


so habe ich mir das vorgestellt, nur will mir das der compiler nicht abnehmen.

mfg
Ulixes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 63

Win Vista Home Premium
Delphi 2009 Professional, XHTML, CSS, PHP
BeitragVerfasst: Sa 28.03.09 12:23 
Hallo,

Versuch es mal so:
ausblenden Delphi-Quelltext
1:
2:
if (Panel1.Caption = 'X'and (Panel2.Caption='X'and (Panel3.Caption='X'then
  label1.Caption:= 'was weis ich ^^';


Weiß aber nicht, ob das sauber ist...ich mach es manchmal so

Mfg

EDIT: Sorry...gerade ein Denkfehler...du musst zu jeder deiner Überprüfungen eine Bedingung schreiben.
Das war dein Fehler.

_________________
"Alles ist möglich, Unmögliches dauert nur ein bisschen länger!"


Zuletzt bearbeitet von Ulixes am Sa 28.03.09 12:28, insgesamt 1-mal bearbeitet
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 28.03.09 12:27 
Wundert mich, dass du da keine Fehlermeldung bekommst :? "incompatible types: boolean and string".

ausblenden Eigentlich müsste das so aussehen:
1:
2:
if (Panel1.Caption = Panel2.Caption) and (Panel2.Caption = Panel3.Caption) then
  ..


Die logischen Operatoren and und or sind übrigens von den umgangssprachlichen verschieden. Wir verwenden "a and b" nämlich auch, um Elemente zu Mengen zusammenzufügen([a] and [b] = [a, b]).

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
And: And(a, b: Boolean): Boolean.
    tr fl
----------
tr- tr fl
fl- fl fl

Or: Or(a, b: Boolean): Boolean.
    tr fl
----------
tr- tr tr
fl- tr fl

->Or ist also die Negation der Spiegelung der Wahrheitstabelle von And an der Mittelachse
  ->Or(a, b) = not(And(not(a), not(b))) = not(not a and not b),

mit not(z: Boolean): Boolean.
z   not(z)
----------
tr-  fl
fl-  tr


mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)


Zuletzt bearbeitet von Hidden am Sa 28.03.09 13:45, insgesamt 3-mal bearbeitet
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Sa 28.03.09 12:27 
ausblenden Delphi-Quelltext
1:
2:
if (Panel1.Caption = 'X'and (Panel2.Caption = 'X'and (Panel3.Caption = 'X'then
   label1.Caption:= 'was weis ich ^^';

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 28.03.09 12:29 
3x Orange unter mir, aber ich korrigiere mal: Du musst das jeweils extra schreiben:

ausblenden Delphi-Quelltext
1:
if (Panel1.Caption = 'X'AND (Panel2.Caption = 'X'AND ...					

bzw.:

ausblenden Delphi-Quelltext
1:
if (Panel1.Caption = 'X'AND (Panel2.Caption = Panel1.Caption) AND ...					

Hier bieten sich dann Variablen an:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
P1 := Panel1.Caption;
P2 := Panel2.Caption 
P3 := Panel3.Caption;

if (P1 = 'X'AND (P2 = P1) AND (P3 = P1) then

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)