Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax on conditional statements 4

Status
Not open for further replies.

Froskoy

Programmer
Jul 25, 2009
18
0
0
GB
Is saying

Code:
if (Intensity=24) or (Intensity=25) then TempGetColour:=RGB(168,168,168);

exactly the same as

Code:
if (Intensity=24 or 25) then TempGetColour:=RGB(160,160,160);

?

Thanks very much,

Froskoy.
 
You should use your first example.

I imagine that the second example will give you a compile time syntax error.


Andrew
Hampshire, UK
 
It compiles fine.... it's a logical error I'm worried about. Will it ultimately give the same result?
 
since the binary operator (or) takes precedence, delphi will first execute the or statement.

so it finally boils down to

Code:
if (Intensity=25) then TempGetColour:=RGB(160,160,160);

because 24 OR 25 = 25

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Another option if the data type supports it.

Code:
if Intensity in [24..25] then 
  TempGetColour:=RGB(168,168,168);

Measurement is not management.
 
Thanks very much whosrdaddy. That's really helpful and makes that sort of thing make more sense to me now so will be helpful in future as well.

Thanks also Glenn9999, that does look neat and something that I hadn't thought of off the top of my head.
 
Code:
procedure TMainForm.xALL;
begin
  repeat
    xManagerALL;
  until (CallPack[0..9].active = false);
end;

Instead of this:
Code:
procedure TMainForm.xALL;
begin
  repeat
    xManagerALL;
  until (CallPack[0].active = false) and
        (CallPack[1].active = false) and
        (CallPack[2].active = false) and
        (CallPack[3].active = false) and
        (CallPack[4].active = false) and
        (CallPack[5].active = false) and
        (CallPack[6].active = false) and
        (CallPack[7].active = false) and
        (CallPack[8].active = false) and
        (CallPack[9].active = false);
end;

It probably wont work though ('Array' and 'ISipCall' incompatible types). I like it though looks SNAZZY! :p I can use it some other time in the future.
 
Yes, that is pretty cool. Thanks for posting that idea.
 
Hi Bamben,

I hate to rain on your parade, but
Code:
procedure TMainForm.xALL;
begin
  repeat
    xManagerALL;
  until (CallPack[0..9].active = false);
end;

won't compile in Delphi. You can either refer to the entire array, or a single element of an array. You can never refer to multiple elements in an array in this way.

In your example, I would probably use

Code:
function AreElementsActive(ALow, AHigh: Integer): Boolean;
var
  c : Integer;
begin
  Result := False;
  for c := ALow to AHigh do
    Result := Result or CallPack[c].Active;
end;

procedure TMainForm.xALL;
begin
  repeat
    xManagerALL;
  until not AreElementsActive(0, 9);
end;

The logic in the line
Code:
Result := Result or CallPack[c].Active;
means that as it loops through the array, Result can become True, but never become False again. That way, if a single element is True, Result will be True.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top