if x <> '' then begin
Result := True;
end else
begin
Result := False;
end;
For when the if
statement will be executed?
if x <> '' then begin
Result := True;
end else
begin
Result := False;
end;
For when the if
statement will be executed?
Basic constructs like this behave in Pascal Script the same as in Pascal.
Free Pascal documentation for If..then..else
statement says:
The expression between the
if
andthen
keywords must have aBoolean
result type. If the expression evaluates toTrue
then the statement following thethen
keyword is executed.If the expression evaluates to
False
, then the statement following theelse
keyword is executed, if it is present.
The expression x <> ''
means: the (string) variable x
not equals an empty string.
So overall, the code does: If x
is not an empty string, set Result
to True
, else set Result
to False
. Note that Result
is a special identifier used to set a return value of a function in which it is used.
Actually, the code can be simplified to a single statement:
Result := (x <> '');
(brackets are for readability only, they are not required)