Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ in win32 DELPHI

Is it possible to use LINQ in win32 DELPHI applications

like image 841
Jlouro Avatar asked Jan 03 '09 23:01

Jlouro


3 Answers

Delphi 2009 has generics, class helpers and anonymous method support, but not lambda, extension methods or type inference. Lambda expressions are probably coming in a future version of Delphi, but they are not on the official road map yet (a new one should be coming soon hopefully). Also Delphi for Win32 does not have access to all the LINQ libraries.

So the short answer is NO, you can't do LINQ in Win32 Delphi. You can how ever do some similar things, and you can technically even access LINQ through COM (as you can with any .NET classes), but it would kind of defeat the point without the cool LINQ syntax.

LINQ is really a .NET technology. While Delphi will most likely develop the language features that make LINQ possible, the underlying .NET libraries are for .NET development only.

I would suggest using RemObject Data Abstract or similar.

like image 107
Jim McKeeth Avatar answered Nov 05 '22 23:11

Jim McKeeth


Yes and No. LINQ can really be thought of as two different items.

The first is the SQL like query syntax. It's what allows you to write the following in C#.

var query = from it in "foobar" select Char.ToUpper(it);

For delphi to use this version of LINQ, it would need to add explicit syntax support. AFAIK this does not exist.

Under the hood though, all LINQ queries are translated into a set of query expressions. These typically involve a heavy use of lambda expressions and closures. The above code is equivalent to the following non-SQL syntax version.

var query = "foobar".Select(x => Char.ToUpper(x));

I don't know the level of lambda or delegate support in Delphi but it should be possible to access LINQ in this method from Delphi.

like image 23
JaredPar Avatar answered Nov 05 '22 22:11

JaredPar


I don't know in what version of Delphi it appeared, but in XE we have 'object functions' that can be made as closures or near equal lambda expressions.

So, as of today (26/06/2011) it is near possible to have LINQ-like expressions in Delphi (the 2nd form).

like image 28
XYZ Avatar answered Nov 05 '22 23:11

XYZ