Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi and im if verhält sich seltsam (https://www.delphipraxis.net/74220-im-if-verhaelt-sich-seltsam.html)

xZise 30. Jul 2006 20:36


and im if verhält sich seltsam
 
(ich kannte keinen besseren Titel! SRY!)

Ich habe eine Abfrage, die mir den Koffer errechnet. Nun kann es sein, dass gar keiner selektiert ist, deshalb mache ich diese Abfrage:
Delphi-Quellcode:
if (col >= 0) and ((row = 0) and (col <= 7)) or ((row = 1) and (col <= 6)) or ((row = 2) and (col <= 5)) or ((row = 3) and (col <= 4)) then begin
Wenn diese wahr ist, dann ist ein Koffer selektiert!
col ist der Koffer von Links und row ist die Zeile.

(Berechnung in Mousemove:
Delphi-Quellcode:
row := Floor(Y / 70);
side := Floor(5 + row * 32.5);
col := Floor((x - side) / 70);
)

Wenn jetzt col kleiner als null ist (also der erste teil "col >= 0" nicht wahr ist), dann springt er trotzdem rein!
Obwohl bei And es eigentlich beides wahr sein muss! (1 and 1 = 1 aber 0 and 1 = 0!)

mkinzler 30. Jul 2006 20:40

Re: and im if verhält sich seltsam
 
Wenn der erste Term immer wahr sein muß, dann fehlt eine Klammer
Delphi-Quellcode:
if (col >= 0) and (((row = 0) and (col <= 7)) or ((row = 1) and (col <= 6)) or ((row = 2) and (col <= 5)) or ((row = 3) and (col <= 4))) then begin

sakura 30. Jul 2006 20:41

Re: and im if verhält sich seltsam
 
Dir fehlt eine Klammer um sämtliche ors ;)
Delphi-Quellcode:
if (col >= 0) and   (    ((row = 0) and (col <= 7)) or ((row = 1) and (col <= 6)) or ((row = 2) and (col <= 5)) or ((row = 3) and (col <= 4))  )   then begin
...:cat:...

xZise 30. Jul 2006 20:42

Re: and im if verhält sich seltsam
 
Ah ^^ Danke ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz