3

I am planning to write a Live Binding source expression for TCheckBox:

SourceExpression = '(Checked = False) and (Enabled = True)'

When execute the code, an exception prompted:

Expected EOF - trailing text in expression

Is Delphi XE2 Live Binding support boolean operator?

Guillem Vicens
  • 3,936
  • 30
  • 44
Chau Chee Yang
  • 18,422
  • 16
  • 68
  • 132
  • Just a wild guess - have you tried to use `SourceExpression = '(not Checked) and (Enabled)'` ? And why ? Because it hurts my eyes whenever I see `=` in boolean expression :-) But don't have Delphi XE2 right now... – TLama Aug 03 '12 at 09:29
  • 1
    `not Checked` is not supported, so I use `Checked = False` – Chau Chee Yang Aug 03 '12 at 09:46
  • Look at this SO question: [How to write live binding expression that control TEdit.PasswordChar based on TCheckBox.Checked?](http://stackoverflow.com/q/11573434/576719). The accepted answer registers a boolean expression evaluator. – LU RD Aug 03 '12 at 11:17
  • 1
    AFAIK you can't use the logical operators (`and`, `or`, ´not´ , ´xor´, ´shl´, ´shr´) in a LiveBinding expression :(, as workaround you can register a custom method to evaluate the logical operation. – RRUZ Aug 03 '12 at 18:32
  • shl and shr are not logical operators. It's impossible to believe that live bindings don't support logical operators. – David Heffernan Dec 04 '12 at 16:28
  • Impossible to believe, and yet sadly, apparently, true! – David Heffernan Dec 04 '12 at 19:46

1 Answers1

1

No, boolean operators are not supported directly.

From the docu:

You can use the following math symbols in your expressions:

  • Constants: nil True False Pi
  • Arithmetic operators: + - * /
  • Logic operators: = <> < <= > >=
  • Parentheses, (), to change operator precedence.

But you can use the builtin functions IfAll(), IfAny() and IfThen() instead of and, or and not:

SourceExpression := 'IfAll(IfThen(Checked, False, True), Enabled)'

Or you register your own functions.

I tested this 4 XE4, but it should work for XE2 2.

  • A or B: IfAny(A, B)
  • A and B: IfAll(A, B)
  • not A: IfThen(A, False, True)
  • A xor B: IfAll(IfAny(A, B), IfThen(IfAll(A,B), False, True))
Ken White
  • 123,280
  • 14
  • 225
  • 444
yonojoy
  • 5,486
  • 1
  • 31
  • 60