In OOP, we are using Properties to be able to limit access to class members, or to have “calculated” values. In Delphi Native Pascal, a class with 3 properties may look like this:
As there is obviously still some uncertainty if Delphi Prism is really a fully fledged .NET development environment, I’m posting an example below to prove that Prism does allow you to LINQ to SQL:
This is a “Customer” class definition with a manual mapping to a “Customers” table on a SQL Server 2005:
This is the actual LINQ to SQL code that relies on the class definition above:
method MainForm.button2_Click(sender: System.Object; e: System.EventArgs);
var
LCustomers: Table<Customer>;
LDBMain: DataContext;
LConnectionString:String;
begin
LConnectionString := 'Data Source=.\SQLEXPRESS;Initial Catalog=DBDEMOS;Integrated Security=True';
LDBMain := new DataContext(LConnectionString);
LCustomers := LDBMain.GetTable<Customer>();
var USCustomers := from Customer in LCustomers where Customer.Country = 'US' select Customer;
for each Customer in USCustomers do begin
listBox1.Items.Add(Customer.Name);
end;
end;
Interesting to note is that Prism has a very nice name scope mechanism. Even though “Customer” is a Class name, it is also used as local variable in the LINQ and FOR constructs. I am not saying that this is a good practice though
Technically, both “Customer” variables are different variables – which is quite important to understand.
The full demo source can be downloaded here: [download#2].
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!
Delphi Prism comes with a nice “Sync Editing” feature. Unfortunately it’s not enabled by default, because it relies on an external “DXCore” assembly, which is available as free download from DevExpress. This “Sync Edit” works for methods only currently, but it does that in a very intuitive way, you don’t have to remember any shortcuts, just write. As little bonus it also gives you “animated bookmarks”. These bookmarks are used for example when you press CTRL-SHIFT-V to declare a local variable or property (which depends on the name you give).
DevExpress is a component set and productivity plugin vendor who serves the VCL and .NET market. DXCore is a base library which is heavily used by their CodeRush and Refactor products.
To finally enable Sync Editing after installing DXCore you need to copy one file manually. Just follow the steps in this Prism Wiki article.