Use ADO. Net (1) in Delphi through Crosstalk)

Source: Internet
Author: User

Atozed, a company that created a new project (Indy is also engaged in), attempts to build a bridge between native and. net so that Delphi can use. NET components:

Http://www.atozed.com/CrossTalk/index.EN.aspx

Because after ado2.8, Ms is no longer maintained, all of them are transferred to ADO. net, I have always wanted to use its new features, but the project still cannot throw the Delphi environment. This crosstalk seems to be what I want.

After the download, enable Delphi XE, create a project, save, and import the following components into system. Data. dll:

After you press save, The ctsystem_data.pas file is automatically generated under the project directory.

Write a code segment to test it:

uses    Windows, Messages, SysUtils, Variants, Classes, Graphics,   Controls, Forms,  Dialogs,StdCtrls, DB, ADODB, CTmscorlib,CTSystem_Data;procedure TForm4.Button1Click(Sender: TObject);var  vConnection:CTSystem_Data.SqlConnection;  vCommand:SQLCommand;  vReader:SqlDataReader;  vTable:CTSystem_Data.DataTable;  vDataSet:DataSet;  vAdapter:CTSystem_Data.SqlDataAdapter;  vFormatter:BinaryFormatter;begin  vConnection:=SqlConnection.Create('Password=xxx;User ID=sa;Initial Catalog=xxx;Data Source=.');  vConnection.Open;  vCommand:=vConnection.CreateCommand;  vCommand.CommandText:='select UserOID,UserAID from Users';  vReader:=vCommand.ExecuteReader;  vReader.Read;  ShowMessage(vReader.GetString(1));

Haha, success.

Two problems are found:

(1) Many functions with the same name cannot be compiled even with overload. For example:

    function CreateCommand: CTSystem_Data.SqlCommand; overload;    function CreateCommand: TCTObject {Class: System.Data.Common.DbCommand}; overload;

But check the definition of sqlconnection in C #. There are not two createcommands, but one is called createdbcommand:

public SqlCommand CreateCommand();protected override DbCommand CreateDbCommand();

However, because sqlconnection is inherited from dbconnection, and dbconnection does have a dbcommand createdbcommand (); therefore, it seems that it is an automatically generated component that places the methods of the ancestor to itself, it may be a bug where crosstalk automatically generates code, or its functional limitations, because the package components are inherited from tctobject, and there is no inheritance relationship between the package components.

(2) because all. Net elements are encapsulated as descendants of tctobject, the parent-child relationship between the original components will be damaged. For example:

Stream = class(TCTObject)...end;FileStream = class(TCTObject)...end;BinaryFormatter = class(TCTObject)public    procedure Serialize(const aSerializationStream: CTmscorlib.Stream; const aGraph: TCTObject); overload;...end;

The following code does not compile vformatter. serialize:

procedure TForm4.Button1Click(Sender: TObject);var  vConnection:CTSystem_Data.SqlConnection;  vCommand:SQLCommand;  vReader:SqlDataReader;  vTable:CTSystem_Data.DataTable;  vDataSet:DataSet;  vAdapter:CTSystem_Data.SqlDataAdapter;  vFormatter:BinaryFormatter;  vStream:FileStream;begin  vConnection:=SqlConnection.Create('Password=xxx;User ID=sa;Initial Catalog=xxx;Data Source=.');  vConnection.Open;  vAdapter:=SqlDataAdapter.Create('select UserOID,UserAID from Users',vConnection);  vDataSet:=DataSet.Create();  vAdapter.Fill(vDataSet);  ShowMessage(InttoStr(vDataSet.Tables.Count));  ShowMessage(vDataSet.Tables.Item[0].TableName);  vFormatter:=BinaryFormatter.Create();  vStream:=FileStream.Create('D:\ADO.Net.dat',FileMode.CreateNew);  vFormatter.Serialize(vStream,vDataSet.Tables.Item[0]);  vStream.Position:=0;  vStream.Flush;end;

[DCC Error] unit4.pas (53): e2250 there is no overloaded version of 'serialize' that can be called with these arguments
Change the definition to filestream = Class (Stream). After compilation, run the following statement:
Vdataset. Tables. item [0]. tablename
This error occurs:
Project project6.exe raised exception class ectdotnetexception with message 'ambiguousmatchexception: an ambiguous match is found. '.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.