Link to home
Create AccountLog in
Avatar of ChLa
ChLaFlag 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.
ASKER CERTIFIED SOLUTION
Avatar of 8080_Diver
8080_Diver
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of 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.
Avatar of 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.
Avatar of 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;
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
if failed to mention that it gives AV when list = nil
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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-}
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
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.
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.