Opérateur de coalescence
L'opérateur de coalescence est un opérateur binaire qui vaut son opérande de gauche si elle n'est pas interprétable comme false, et son opérande de droite sinon.
L'opérande de droite n'est évaluée que si nécessaire.
var a : Variant = Null;
PrintLn( a ?? 'hello' ); // affiche hello
a := '';
PrintLn( a ?? 'hello' ); // affiche hello
a := 'world';
PrintLn( a ?? 'hello' ); // affiche world
PrintLn( a ?? Dummy() ); // affiche world, et n'appelle pas la fonction Dummy()
PrintLn( a ?? 'hello' ); // affiche hello
a := '';
PrintLn( a ?? 'hello' ); // affiche hello
a := 'world';
PrintLn( a ?? 'hello' ); // affiche world
PrintLn( a ?? Dummy() ); // affiche world, et n'appelle pas la fonction Dummy()
Les valeurs interprétées comme false sont :
- Unassigned
- Null
- nil
- False
- 0
- "" (chaîne vide)