I noticed this block of code today and was wondering if these type of operations are documented somewhere and why it was done this way (Performance, etc).
var
Shift: TShiftState
begin
if [ssShift, ssCtrl] * Shift <> [] then
begin
...
end;
end;
It looks to me from my testing and just looking at the code like this is checking if Shift contains either ssShift
or ssCtrl
. Is this documented behavior or is it just leveraging the fact that the set is actually stored as an integer internally?
The * (multiplication) operator yields the product of its operands. The operands must have an arithmetic or enumeration type. The result is not an lvalue. The usual arithmetic conversions on the operands are performed.
Using the * Operator in Python The * operator is used to multiply numeric values in Python.
An asterisk ( * ) is used to represent the multiplication operator.
The multiplication assignment operator ( *= ) multiplies a variable by the value of the right operand and assigns the result to the variable.
That's not the multiplication operator when used with sets; it's the intersection operator. This is documented, and has been since pre-Delphi days. See Expressions, particularly the section on set operations. They're the standard mathematical operators for union, intersection, sub- and super-sets, equality, inequality, and membership.
Here's a summary of the table from the docs:
Operator Operation Operand Types Result Type Example -------- --------- ------------- ----------- ------- + union set set Set1 + Set2 - difference set set S - T * intersection set set S * T <= subset set Boolean Q <= MySet >= superset set Boolean S1 >= S2 = equality set Boolean S2 = MySet <> inequality set Boolean MySet <> S1 in membership ordinal, set Boolean A in Set1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With