Delphi Framework Class Library

The Library is a Delphi interface representation of the .NET Framework class library which is tightly integrate with the Delphi Host Class Library. This library enables you to accomplish a range of common programming tasks, including tasks such as string management, data collection, data access, database connectivity, cryptography, network communications, file access and many more. In addition to these common tasks, the class library includes type interfaces that support a variety of specialized development scenarios. It also contains interfaces that provide access to system functionality.

Namespaces

The following table represents the classification of the Delphi Framework Class Library Namespaces:

CNClrLib.CodeDom

This namespace contains interfaces that can be used to represent the elements of a source code document and that support the generation and compilation of source code in supported programming languages.

CNClrLib.Collections

This namespace contains interfaces that define various standard, specialized, and generic collection objects.

CNClrLib.Common

This namespace contains interfaces shared among the various namespaces to prevent self circular reference error when compiling your Delphi application.

CNClrLib.ComponentModel

This namespace contains interfaces that implement the run-time and design-time behavior of components and controls.

CNClrLib.Configuration

This namespace contains interfaces for handling configuration data, such as data in machine or application configuration files.

CNClrLib.CSharp

This namespace contains interfaces that support compilation and code generation of source code written in the C# language, and types that support interoperation betwen the dynamic language runtime (DLR) and C#.

CNClrLib.Deployment

This namespace contains interfaces that support deployment of ClickOnce applications.

CNClrLib.DirectoryServices

This namespace contains interfaces that provide access to Active Directory.

CNClrLib.Dynamic

The CNClrLib.Dynamic Linq namespace provides interfaces that support Dynamic Language Runtime.

CNClrLib.Generic.Helper

This namespace contains interfaces and classes to convert .net generic list or nullable types to it equivalent in Delphi.

CNClrLib.IdentityModel

This namespace contains interfaces that are used to provide authentication and authorization for applications.

CNClrLib.Linq

This namespace contains interfaces that support queries that use Language-Integrated Query (LINQ). This includes types that represent queries as objects in expression trees.

CNClrLib.Media

This namespace contains interfaces for playing sound files and accessing sounds provided by the system.

CNClrLib.Messaging

This namespace contains interfaces that enable you to connect to, monitor, and administer message queues on the network and to send, receive, or peek messages.

CNClrLib.Numerics

This namespace contains numeric interfaces that complement the numeric primitives, such as Byte, Double, and Int32 that are defined by the .NET Framework.

CNClrLib.Resources

This namespace contains interfaces that enable developers to create, store, and manage an application's culture-specific resources.

CNClrLib.ServiceModel

This namespace contains the interfaces necessary to build Windows Communication Foundation (WCF) service and client applications.

CNClrLib.ServiceProcess

This namespace contains interfaces that enable you to implement, install, and control Windows service applications and extend design-time support for Windows service applications.

CNClrLib.Speech

This namespace contain interfaces that support speech recognition.

CNClrLib.SqlServer

This namespace contains interfaces that are specific to the integration of the Microsoft .NET Framework common language runtime (CLR) into Microsoft SQL Server, and the SQL Server database engine process execution environment.

CNClrLib.System

This namespace contains fundamental interfaces that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.

CNClrLib.Text

This namespace contains interfaces for character encoding and string manipulation. It also enables you to process text using regular expressions.

CNClrLib.Threading

This namespace contains interface that enable multithreaded programming. The namespace provides types that simplify the work of writing concurrent and asynchronous code.

CNClrLib.Timers

This namespace provides the Timer component, which allows you to raise an event on a specified interval.

CNClrLib.Transactions

This namespace contains interfaces that support transactions with multiple, distributed participants, multiple phase notifications, and durable enlistments.

CNClrLib.Win32

This namespace provides interface that handle events raised by the operating system, that manipulate the system registry, and that represent file and operating system handles.

CNClrLib.Xaml

This namespace contains interface that support parsing and processing the Extensible Application Markup Language (XAML).

CNClrLib.Xml

This namespace contains interface for processing XML. It contains interfaces that support serialization of XML documents or streams, XSD schemas, XQuery 1.0 and XPath 2.0, and LINQ to XML.

CNClrLib.Data

This namespace contains interfaces for accessing and managing data from diverse sources. These form the ADO.NET architecture and ADO.NET data providers. For example, providers are available for SQL Server, Oracle, ODBC, and OleDB. It contains interfaces for ADO.NET Entity Data Model (EDM) and WCF Data Services.

CNClrLib.EnterpriseServices

This namespace contains interfaces that define the COM+ services architecture, which provides an infrastructure for enterprise applications. It supports Compensating Resource Manager (CRM), a COM+ service that enables non-transactional objects to be included in Microsoft Distributed Transaction Coordinator (DTC) transactions.

CNClrLib.Printing

This namespace contains interfaces that support printing, that provide access to the properties of print system objects and enable rapid copying of their property settings to another object of the same type, and that support the interconversion of managed .net System.PrintTicket objects and unmanaged GDI DEVMODE structures.

CNClrLib.VisualBasic

This namespace contains classes that support compilation and code generation using the Visual Basic language. The namespace also contain types that provide services to the Visual Basic compiler and types that include support for the Visual Basic application model, the My namespace, lambda expressions, and code conversion.

CNClrLib.Security

This namespace contains interfaces for the .NET Framework security system and permissions and provides interfaces that control access to and audit securable objects, allow authentication, provide crytographic services, control access to operations and resources based on policy, and support rights management of application-created content.


CNClrLib.Drawing

This namespace contains interfaces that support basic GDI+ graphics functionality and advanced two-dimensional and vector graphics functionality, advanced imaging functionality, and print-related and typographical services. The namespace also contains interfaces that extend design-time user-interface logic and drawing.


CNClrLib.Windows

This namespace contains interface used in Windows Presentation Foundation (WPF) applications, Windows forms and web applications, including animation clients, user interface controls, data binding, and type conversion.




CNClrLib.Management

This namespace contains interfaces that provide access to management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure. These namespaces also contain types necessary for instrumenting applications.


CNClrLib.IO

This namespace contains interfaces that support input and output, including the ability to read and write data to streams either synchronously or asynchronously, to compress data in streams, to create and use isolated stores, to map files to an application's logical address space, to store multiple data objects in a single container, to communicate using anonymous or named pipes, to implement custom logging, and to handle the flow of data to and from serial ports.

CNClrLib.Web

This namespace contains interface that enable browser/server communication which include types that support ASP.NET forms authentication, application services, data caching on the server, ASP.NET application configuration, dynamic data, HTTP handlers, JSON serialization, incorporating AJAX functionality into ASP.NET, ASP.NET security, and web services.


CNClrLib.Diagnostics

This namespace contains interfaces that enable you to interact with system processes, event logs, and performance counters. It contains interfaces to support contracts, to extend design-time support for application monitoring and instrumentation, to log event data using the Event Tracing for Windows (ETW) tracing subsystem, to read to and write from event logs and collect performance data, and to read and write debug symbol information.

CNClrLib.Device

This namespace allows application developers to easily access the computer's location by using a single API. Location information may come from multiple providers, such as GPS, Wi-Fi triangulation, and cell phone tower triangulation. The CNClrLib.Device interfaces provide a single API to encapsulate the multiple location providers on a computer and support seamless prioritization and transitioning between them.

CNClrLib.Runtime

This namespace contains interfaces that support an application's interaction with the common language runtime, and types that enable features such as application data caching, advanced exception handling, application activation within application domains, COM interop, distributed applications, serialization and deserialization, and versioning. Additional namespaces enable compiler writers to specify attributes that affect the run-time behavior of the common language runtime, define a contract for reliability between a set of code and other code that takes a dependency on it, and implement a persistence provider for Windows Communication Foundation (WCF).

CNClrLib.Net

This namespace contains interfaces that provide a simple programming interface for a number of network protocols, programmatically access and update configuration settings for the CNClrLib .Net namespaces, define cache policies for web resources, compose and send e-mail, represent Multipurpose Internet Mail Exchange (MIME) headers, access network traffic data and network address information, and access peer-to-peer networking functionality. It also provide a managed implementation of the Windows Sockets (Winsock) interface and provide access to network streams for secure communications between hosts.



Source Code Examples

Example 1

How to create and fill a DataSet from the Northwind database.

Delphi
program NorthwindDataSet;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  SysUtils,
  CNClrLib.Enums,
  CNClrLib.Data,
  CNClrLib.Core;

var
  Console: _Console;

  procedure ConnectToData(connectionString: string);
  var
    connection: _SqlConnection;
    adapter: _SqlDataAdapter;
    command: _SqlCommand;
    dataSet: _DataSet;
    productsAdapter: _SqlDataAdapter;
    productsCommand: _SqlCommand;
    parentColumn,
    childColumn: _DataColumn;
    relation: _DataRelation;
  begin
    //Create a SqlConnection to the Northwind database.
    connection := CoSqlConnection.CreateInstance(connectionString);

    //Create a SqlDataAdapter for the Suppliers table.
    adapter := CoSqlDataAdapter.CreateInstance;

    // A table mapping names the DataTable.
    adapter.TableMappings.Add_2('Table', 'Suppliers');

    // Open the connection.
    connection.Open;
    Console.WriteLine_14('The SqlConnection is open.');

    // Create a SqlCommand to retrieve Suppliers data.
    command := CoSqlCommand.CreateInstance(
        'SELECT SupplierID, CompanyName FROM dbo.Suppliers;',
        connection);
    command.CommandType := CommandType_Text;

    // Set the SqlDataAdapter's SelectCommand.
    adapter.SelectCommand := command;

    // Fill the DataSet.
    dataSet := CoDataSet.CreateInstance('Suppliers');
    adapter.Fill(dataSet);

    // Create a second Adapter and Command to get
    // the Products table, a child table of Suppliers.
    productsAdapter := CoSqlDataAdapter.CreateInstance;
    productsAdapter.TableMappings.Add_2('Table', 'Products');

    productsCommand := CoSqlCommand.CreateInstance(
        'SELECT ProductID, SupplierID FROM dbo.Products;',
        connection);
    productsAdapter.SelectCommand := productsCommand;

    // Fill the DataSet.
    productsAdapter.Fill(dataSet);

    // Close the connection.
    connection.Close();
    Console.WriteLine_14('The SqlConnection is closed.');

    // Create a DataRelation to link the two tables
    // based on the SupplierID.
    parentColumn := dataSet.Tables.Item_1['Suppliers'].Columns.Item_1['SupplierID'];
    childColumn := dataSet.Tables.Item_1['Products'].Columns.Item_1['SupplierID'];
    relation := CoDataRelation.CreateInstance('SuppliersProducts', parentColumn, childColumn);
    dataSet.Relations.Add(relation);

    Console.WriteLine_15('The {0} DataRelation has been created.', relation.RelationName);
  end;

  function GetConnectionString: string;
  begin
    // To avoid storing the connection string in your code,
    // you can retrieve it from a configuration file.
    Result := 'Data Source=(local);Initial Catalog=Northwind;' +
              'Integrated Security=SSPI';
  end;

var
  connectionString: string;
begin
  try
    Console := CoConsole.CreateInstance;
    connectionString := GetConnectionString;
    ConnectToData(connectionString);
  except
    on E: Exception do
    begin
      Console.WriteLine_14(E.message);
    end;
  end;
end.

Example 2

How to use Enumerable methods such as First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, ElementAt, ElementAtOrDefault, Count, Contains, Sum, Min, Max.

Delphi
program LinqWithEnumerableInterface;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils,
  CNClrLib.Host,
  CNClrLib.Host.Helper,
  CNClrLib.Collections,
  CNClrLib.DynamicLinq,
  CNClrLib.Linq,
  CNClrLib.Core;

var
  Console: _Console;
  IntList: _GenericList;
  intType: _Type;
  Enumerable: _Enumerable;
  ListEnumerable: _GenericIEnumerable;
  I: Integer;
begin
  Console := CoConsole.CreateInstance;
  //Integer Type
  intType := TClrAssembly.GetType('System.Int32');

  //Integer Collections
  IntList := CoGenericList.CreateInstance(intType);
  IntList.Add(33);
  IntList.Add(45);
  IntList.Add(50);
  IntList.Add(45);
  IntList.Add(34);
  IntList.Add(23);
  IntList.Add(67);

  Console.WriteLine_14('Elements in the List:');
  for I := 0 to IntList.Count - 1 do
    Console.WriteLine_8(IntList[I]);

  //Get GenericIEnumerable from the GenericList
  ListEnumerable := IntList.AsGenericIEnumerable;
  Enumerable := CoEnumerable.CreateInstance;

  Console.WriteLine_14('Enumerable Interface Methods: ');

  Console.WriteLine_15('First:              {0}', Enumerable.First(intType, ListEnumerable));
  Console.WriteLine_15('FirstOrDefault:     {0}', Enumerable.FirstOrDefault(intType, ListEnumerable));
  Console.WriteLine_15('Last:               {0}', Enumerable.Last(intType, ListEnumerable));
  Console.WriteLine_15('LastOrDefault:      {0}', Enumerable.LastOrDefault(intType, ListEnumerable));

  try
    Console.WriteLine_15('Single:             {0}', Enumerable.Single(intType, ListEnumerable));
  except
    on E: Exception do
      Console.WriteLine_15('Single:           {0}', E.Message);
  end;

  try
    Console.WriteLine_15('SingleOrDefault:    {0}', Enumerable.SingleOrDefault(intType, ListEnumerable));
  except
    on E: Exception do
      Console.WriteLine_15('SingleOrDefault:  {0}', E.Message);
  end;

  Console.WriteLine_15('ElementAt:          {0}', Enumerable.ElementAt(intType, ListEnumerable, 4));
  Console.WriteLine_15('ElementAtOrDefault: {0}', Enumerable.ElementAtOrDefault(intType, ListEnumerable, 5));
  Console.WriteLine_15('Count:              {0}', Enumerable.Count(intType, ListEnumerable));
  Console.WriteLine_15('Contains:           {0}', Enumerable.Contains(intType, ListEnumerable, 30));
  Console.WriteLine_15('Contains:           {0}', Enumerable.Contains(intType, ListEnumerable, 34));
  Console.WriteLine_15('Sum:                {0}', Enumerable.Sum(ListEnumerable));
  Console.WriteLine_15('Min:                {0}', Enumerable.Min(ListEnumerable));
  Console.WriteLine_15('Min with Int32 Type:{0}', Enumerable.Min_1(intType, ListEnumerable));
  Console.WriteLine_15('Max:                {0}', Enumerable.Max(ListEnumerable));
  Console.WriteLine_15('Max with Int32 Type:{0}', Enumerable.Max_1(intType, ListEnumerable));
  Console.WriteLine_15('Average:            {0}', Enumerable.Average(ListEnumerable));

  Console.ReadLine();
end.