ChLa
asked on
Is there an If, Then, Else statement in Delphi ?
Hi,
I wonder if Delphi supports an if, then, else statement. I have never been able to get one working in Delphi. When I search through the help files that come with Delphi, I can only find information on Visual Basic, and C++. I find the included help files very hard to use and rarely find what I am looking for. This makes Programmers Exchange indispensible.
Thank you
I wonder if Delphi supports an if, then, else statement. I have never been able to get one working in Delphi. When I search through the help files that come with Delphi, I can only find information on Visual Basic, and C++. I find the included help files very hard to use and rarely find what I am looking for. This makes Programmers Exchange indispensible.
Thank you
ASKER CERTIFIED 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.
I missed a then in my second example
if (Condition) then
begin
//your block of statements
end
else if (OtherCondition) then
begin
//other block
end
else
begin
//some more
end;
If you are comparing multiple ordinal values, you can use the case statement as well
eg
case Value of
1: ShowMessage('one');
2: ShowMessage('two');
3: ShowMessage('three');
4: ShowMessage('four');
else
ShowMessage('I do not know');
end;
if (Condition) then
begin
//your block of statements
end
else if (OtherCondition) then
begin
//other block
end
else
begin
//some more
end;
If you are comparing multiple ordinal values, you can use the case statement as well
eg
case Value of
1: ShowMessage('one');
2: ShowMessage('two');
3: ShowMessage('three');
4: ShowMessage('four');
else
ShowMessage('I do not know');
end;
complex help ?
the best help system was in delphi 7
the examples are somewhat lacking
your probably looking for the compact version of if then ?
you need to use the math and strutils units
uses StrUtils, Math;
var x, y, z: integer;
begin
z := IfThen(X>1, 1, 0);
y := IfThen(Z=1,2,1);
for strings:
var s, r: string;
begin
r := 'Test';
s := IfThen(r = 'Test', 'yes', 'no');
the best help system was in delphi 7
the examples are somewhat lacking
your probably looking for the compact version of if then ?
you need to use the math and strutils units
uses StrUtils, Math;
var x, y, z: integer;
begin
z := IfThen(X>1, 1, 0);
y := IfThen(Z=1,2,1);
for strings:
var s, r: string;
begin
r := 'Test';
s := IfThen(r = 'Test', 'yes', 'no');
is It a fun?
Of course delphi like other programming language has if then else and its format is like below
if (condition) then
begin
(True Statements)
end
else
begin
(False Statements)
end
e.g.
if 1=2 then
ShowMessage('1=2')
else ShowMessage('1<>2')
Of course delphi like other programming language has if then else and its format is like below
if (condition) then
begin
(True Statements)
end
else
begin
(False Statements)
end
e.g.
if 1=2 then
ShowMessage('1=2')
else ShowMessage('1<>2')
ASKER
thank you for your help
"There are two forms of if statement: if...then and the if...then...else. The syntax of an if...then statement is
if expression then statement
where expression returns a Boolean value. If expression is True, then statement is executed; otherwise it is not. For example,
if J <> 0 then Result := I/J;
The syntax of an if...then...else statement is
if expression then statement1 else statement2"