Where (keyword)
From The Oxygene Language Wiki
This is a Language topic
Feel free to add your notes to this topic below.
Generics context
Exception filters
where is also used in Exception filters. Exception filters allow you to use more complex logic than just a type check in your except blocks.
Example
try // ... except on E: SocketException where E.Errorcode = 10054 do begin // connection was closed gracefully end; on E: Exception do begin // any other error, including other SocketExceptions end; end;
Query Expressions context
In the Query Expressions it's possible to filter data with the where clause:
var x := from c in MyCustomers where c.City = 'London';
Analogous to the similar syntax in a for each loop, this declares a new variable ("c") that will represent the individual elements of the sequence (in this case, the customers) in the rest of the query. Again similar to the for each loop, the type of "c" is inferred from the context – since the compiler knows that "MyCustomers" is a "sequence of Customer", it can infer that "c" must be a "Customer".
If you want, you can expand this syntax to explicitly state the type of "c", by writing "from c: Customer in ...".
In the where clause, "c" is reused as part of the filter expression, and that we get the full benefits of strong typing, as we can access the City property. The where clause can contain any statement resulting in a Boolean value, and it is important to note that this is real, compiled code, and that you can perform any action here that you could perform elsewhere in your application – including complex Boolean logic, or even calling other methods of your application (or the "Customer" class). This is not a condition that is stored as a string and somehow parsed at runtime (as is often the case when dealing with traditional database filters and passing hard coded SQL from client application to back-end server, in traditional code), but real 100% Delphi Prism code.
After executing the above statement, variable "x" would now contain a newly created sequence, containing only those customers living in London.
See Also
Area: Oxygene Language
Compiler version: Oxygene 5
Language Glossary — Keywords — Types — FAQ — How To