Delphi Prism - new language features for Delphi .NET developers

Posted by on in Blogs
Delphi Prism brings a lot of new language features for .NET development, you will see a much more .NET language friendly and more dynamic language, at the same time language features you won't see in other .NET languages.

This post starts to show some new features on the Delphi Prism language.

You always use procedure and function words to declare a method, in Delphi Prism you can continue using, but now you have this new syntax.

type
ConsoleApp = class
public
class method Main;
method loopsTesting; // This is a procedure
method fillData : sequence of Country; // This is a function
var
Countries :   sequence of Country;
end;

Query Expressions

Based upon its sequence type, Delphi Prism provides a powerful syntax for working on sequences in a syntax similar to SQL. Query Expressions enable you to perform actions such as filtering, sorting, partitioning and joining of data in sequences in an intuitive way, and providing full compile-time type checking and Intellisense. Much like sequences themselves, Query Expressions can be backed by in-memory data or information from remote sources.

Actions performed through query statements might be either performed locally on in memory data, or be processed on the data back-end before data is actually transferred.For example, sorting a sequence using the "order by" clause will work seamlessly, for an "array of String" or for a database table containing millions of records. In the case of the array, the sorting will happen on the local system, but for the data table, the back-end SQL database can handle the sorting as part of the data retrieval. The same concepts would apply to filtering ("where" clause) and other operations.

Look the example:

Class definition

type Customer = public class

property FirstName: String;

property LastName: String;

property Age: Integer;

property Street: String;

property City: String;

property Country: String;

property DateOfBirth: DateTime;

property Orders: sequence of Order;

end;

Order = public class

property OrderID: String;

property OrderDate: DateTime;

property Total: Double;

end;

  • Returning all Customers with more them 30 years old
    for each from c in Customers where c.Age > 30 do
    ...

  • Returning all Customer with more them 30 years old and add First Name and Last Name to the variable n
    for each from c in Customers where c.Age > 30 select c.FirstName+' '+c.LastName into n do
    ...


Would you like to know more about the new Delphi Prism Language, visit Delphi Prism Wiki - language section


Comments

  • Guest
    Mohammed Nasman Tuesday, 28 October 2008

    Andreano, Could you please fix the formatting in the above code?, it didn't' looks good in FF3

  • Guest
    Junior/RO Tuesday, 28 October 2008

    Andreano, o assunto é interessantíssimo mas está horrível pra ler o código.

  • Guest
    Andreano Lanusse Wednesday, 29 October 2008

    Sorry guys, now is fixed

  • Guest
    Kryvich Wednesday, 29 October 2008

    Andreano, you forgot to declare the Age property in Customer. Or I've missed something?

  • Guest
    Kryvich Wednesday, 29 October 2008

    Same with FirstName and LastName properties.

  • Guest
    Andreano Lanusse Wednesday, 29 October 2008

    Both are there

  • Guest
    FDCastel Friday, 31 October 2008

    This is not Delphi. This is the Chrome/Oxygene language (albeit a very good one). Who Embarcadero wants to fool? Just calling it "Delphi" would not help to fill the large gap (and significant differences) between the two languages.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: