IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphiOperators  Print This     

Cross Ref > Operators

By Mike Prestwood

Delphi versus Corel Paradox: A side by side comparison between Delphi and Corel Paradox.

 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

Assignment

[Other Languages] 

Languages Focus

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

Delphi:   :=

Delphi uses := for it's assignment operator.

Syntax Example:
var
  FullName: String;
  Age: Integer;
begin
  FullName := "Randy Spitz";
Age := 38;
end
Corel Paradox:   =

ObjectPAL uses = for it's assignment operator.

Syntax Example:  
var
 FullName String
   Age SmallInt
endVar
  
FullName = "Randy Spitz"
Age = 42




Comparison Operators

[Other Languages] 

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

Delphi:   =, <>

Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Syntax Example:
//Does Delphi evaluate the math correctly? Yes!
//Refer to math.pas MaxSingle for more info.
if (0.1 + 0.1 + 0.1 = 0.3) then
ShowMessage('correct')
else
ShowMessage('not correct')
Corel Paradox:   =, <>

Common comparison operators:

= equal
<> not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Syntax Example:
'Does ObjectPAL evaluate the math correctly? No!
If .1 + .1 + .1 = .3 Then
msgInfo("", "correct")
Else
msgInfo("", "not correct")
endIf




Empty String Check

[Other Languages] 

Languages Focus

An empty string is a zero length string, a string that is equal to null (""), or not assigned. In some languages, you can check if a string is empty by comparing it to an empty string (""). Some languages distinguish between nil and null ("") so checking if the length is 0 is easier.

Delphi:   length(s) = 0

Length() or SizeOf() will correctly identify an unassigned string variable or an empty string.

Syntax Example:
if length(s) = 0 then
  ShowMessage('empty string');
Corel Paradox:   isBlank() or not isAssigned()

In ObjectPAL, an empty variable can be unassigned (essentially null) or blank (equivalent to ""). You have to use both isBlank and isAssigned to check for an empty string.

Syntax Example:
var
 s String
endVar
  
;s = ""  ;Uncomment to test 2nd case.
 
if isBlank(s) or not isAssigned(s) Then
 msgInfo("", "empty string")
endIf




Logical Operators

[Other Languages] 

Languages Focus

Logical operators perform conditional and, or, and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that, if this is an expression returning true, then that is never executed.

Delphi: 

Delphi logical operators:

and and, as in this and that
or or, as in this or that
not Not, as in Not This
xor either or, as in this or that but not both

The Delphi compiler default is to short circuit multi argument boolean expressions when the result is known before the evaluation completes. To disable short circuiting, use the {$B+} compiler directive. To reset it back to the compiler default of short circuting, use the {$B-} compiler directive.

Syntax Example:
//Given expressions a, b, c, and d:
if Not (a and b) and (c or d) then
  //Do something.
Corel Paradox: 

ObjectPAL logical operators:

and and, as in this and that
or or, as in this or that
Not Not, as in Not This

Like VBA, ObjectPAL never short circuits. Given the expression this or that as well as this and that, if this evaluates to false, then that is still executed.

Syntax Example:
;Given expressions a, b, c, and d:
if Not (a and b) and (c or d) then
  ;Do something.
endIf




String Concatenation

[Other Languages] 
Delphi:  "String Concatenation" +

Use the + operator to concatenate two strings. Use IntToStr to convert an integer to a string and FloatToStr to convert a floating point number to a string.

Syntax Example:
var 
  FirstName : String; 
  LastName : String;
begin 
  FirstName := 'Mike'; 
  LastName := 'Prestwood';
  ShowMessage('Full name: ' + FirstName + ' ' + LastName);
  
  ShowMessage(FloatToStr(3.2));
end;
Corel Paradox:  "String Concatenation" +

String literals s are limited to 255 characters but you can simply add two strings together as in:

s = "A long string." + "Another long string."
Syntax Example:
var
FirstName  String
  LastName  String
endVar
 
FirstName  = "Mike"
LastName  = "Prestwood"
msgInfo("", "Full name: " + FirstName + " " + LastName)




Unary Operators

[Other Languages] 

General Info: Unary Operator

An operation with only one operand (a single input). Common unary operators include + plus, - minus, and bitwise not. Some operators can function as both unary and binary operators. For example, + and - operators can serve as either.

Languages Focus

What unary operators are supported in additoin to the standard plus, minus, and bitwise not.

Delphi: 

An operation with only one operand (a single input). In Object Pascal, a unary operator has the highest precedence and always precedes its operand (for example, -B), except for the  ^ pointer operator, which follows its operand (for example, P^). In addition to the obvious +, -, and Not operators, Delphi also offers:

^ Pointer
@ returns the address of a variable, function, procedure, or method; a pointer to its operand.
inc() Increment
dec() Decrement

The TYPE operator is also a unary operator and is valuated at compile time. The TYPE operator returns the size in bytes of the operand,

More Info / Comment
Corel Paradox: 

The ObjectPAL unary operators are:

+
-
Not

More Info / Comment




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]