ChLa
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
If (JamShellList1.SelectedFil es.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.SelectedFi les.Count' , JamShellList1.SelectedFile s.Count,
'not SizeInhibit', IfThen(not SizeInhibit, 1, 0),
'TimesThroughRSLV', TimesThroughRSLV,
'TimesThroughLSLV', TimesThroughLSLV]));
If (JamShellList1.SelectedFil es.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;
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.SelectedFi
'not SizeInhibit', IfThen(not SizeInhibit, 1, 0),
'TimesThroughRSLV', TimesThroughRSLV,
'TimesThroughLSLV', TimesThroughLSLV]));
If (JamShellList1.SelectedFil
AddLog could be something simple like adding it to a memo
procedure TForm1.AddLog(Msg: string);
begin Memo.Lines.Add(Msg); end;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if failed to mention that it gives AV when list = nil
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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-}
{$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.SelectedFil es.Count > 0) and (SizeInhibit = False) and ((A > 2) or (B > 2)) then
A := TimesThroughRSLV
B := TimesThroughLSLV
If (JamShellList1.SelectedFil
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.
ASKER
If (JamShellList1.SelectedFil
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.