Avatar of ChLa
ChLa
Flag for United States of America asked on

Using "or" with "and" in delphi

Hi,

I know I can do this:

 if (X = 1) and (Y = 6) and (M = 4) then

but how can I do this ?:

 if (X = 1) and (Y = 6) and (M = 4) and ((V > 3) or (Q = 9)) then

The way I am using "or" just isn't working.
Delphi

Avatar of undefined
Last Comment
vk3kjc

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
8080_Diver

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ChLa

ASKER
Here's the actual line in my program:

If (JamShellList1.SelectedFiles.Count > 0) and (SizeInhibit = False) and ((TimesThroughRSLV > 2) or (TimesThroughLSLV > 2))
            then

It seems the second possibility in "or"...(TimesThroughLSLV > 2))...isn't happening.
Perhaps it is something else. If this looks good I'll look elsewhere.
ChLa

ASKER
Sorry, it is the first one that isn't happening,. I just reversed them and it is now the second one not happening. This must mean the problem is elsewhere. Your comment made me find this so I will award you the points. Thanks.
Geert G

If (JamShellList1.SelectedFiles.Count > 0) and not SizeInhibit and ((TimesThroughRSLV > 2) or (TimesThroughLSLV > 2)) then

the or will be taken together

have you evaluated with some log or debugging ?
addLog(Format('%s=%d, %s=%d, %s=%d, %s=%d',
  ['JamShellList1.SelectedFiles.Count', JamShellList1.SelectedFiles.Count,
   'not SizeInhibit', IfThen(not SizeInhibit, 1, 0),
   'TimesThroughRSLV', TimesThroughRSLV,
   'TimesThroughLSLV', TimesThroughLSLV]));
   
If (JamShellList1.SelectedFiles.Count > 0) and not SizeInhibit and ((TimesThroughRSLV > 2) or (TimesThroughLSLV > 2)) then

AddLog could be something simple like adding it to a memo
procedure TForm1.AddLog(Msg: string);
begin Memo.Lines.Add(Msg); end;
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
developmentguru

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Geert G

if failed to mention that it gives AV when list = nil
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
developmentguru

Surround may not have been the right word... if the normal is to have it off (which the link says it is) then you could surround your code like this:

{$B+}
  //Your code here
{$B-}
vk3kjc

I gather TimesThroughRSLV and TimesThroughLSLV are routines or procedures that you want evaluated each time the the statement is processed. If that is the case you could set each to a variable prior to that statement.

    A := TimesThroughRSLV
    B := TimesThroughLSLV
   If (JamShellList1.SelectedFiles.Count > 0) and (SizeInhibit = False) and ((A > 2) or (B > 2)) then
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
8080_Diver

I still have to wonder why, given that the bit of the code under all this discussion is an OR clause, it matters whether or not the secopnd/ part of the OR clause is "executed"/"examined".  In the OR clause, all it takes is one of the halves to be TRUE for the whole clause to be considered TRUE.  That's why the default setting is the "quick-exit" option.
vk3kjc

Because ChLa has detected that one of the two tests in the or clause was not processed it obviously does matter. This could only be due to TimesThroughRSLV and TimesThroughLSLV being routines or functions that do something that is required to happen each time the if statement is evaluated.