There are a couple of people who have asked if LINQ can be used with the new Delphi .NET version aka Delphi Prism.  The cool thing is that with Prism you can utilize all available .NET technologies. LINQ though, requires some additional compiler support – to allow for the “compilable query statements”.

The good news is, RemObjects implemented all required compiler support! Excellent!

See the simple example below:


method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
var
lCustomer: Customer;
lCustomers : List<Customer>;
begin
lCustomers := new List<Customer>;

lCustomer := new Customer;
lCustomer.Name := 'Olaf';
lCustomer.Country := 'Germany';
lCustomers.Add(lCustomer);

lCustomer := new Customer();
lCustomer.Name := 'Jim';
lCustomer.Country := 'USA';
lCustomers.Add(lCustomer);

//Inline declaration using type inference
var GermanCustomers :=
from Customer in LCustomers
where Customer.Country.Equals('Germany');

//Has nothing to do with LINQ, but that's type inference too:
for Customer in GermanCustomers do begin
listBox1.Items.Add(Customer.Name);
end;
end;

Interesting to notice is how the variables “GermanCustomers” and “Customers” are declared. They are both declared inline using type inference – which is one of the important enhancements over Delphi Win32.

See the Prism Wiki for details on LINQ.

  • Vegar Vikan

    I have seen many examples and posts on Prism/Oxygen and LINQ, but never a single one have mentioned LINQ to SQL ot Entity Framework.
    Is it possible to do LINQ to SQL in Prism?

  • http://www.monien.net/blog Olaf Monien
blog comments powered by Disqus
CodeGear Technology Partner