In Delphi.NET, Vcl.net has two points that are quite regrettable:
1. You cannot use ADO (DBGO), but according to Levi, this component will be available later.
2. You cannot use the ado.net and BDP, which will be the subject of my article.
In Borland's Delphi communication area, I've seen Danny say, "In Delphi.NET Vcl.net can invoke WinForm components, and WinForm can also invoke vcl.net components."
In order to verify the first sentence, try the next, in the vcl.net can be used. NET components, such as direct uses System.Data.SqlClient, and direct use of SqlConnection classes. That is, although the. NET component is not visible in the Vcl.net palette, all the. NET component classes, Vcl.net are available! However, the Ado.net dataset is not compatible with the Vcl.net DataSet component, so the data-aware component cannot be invoked directly. However, looking at Levi's inside VCL knew that there was a adonetconnector component that used this component to enable Ado.net to support the use of data-aware components.
First, the DLL for the Vcl.net component has a Borland.Vcl.Design.AdoNet.dll under Bds2.0bin, click Install. NET component menu, and then on the form's. NET VCL Add this DLL to the Components page to see the Adonetconnector component. Then add a dbgrid,db....,datasoure ..., just datasource.dataset:=adonetconnector1. The other is the same as the original Delphi, it can be. The same method is also effective for the BDP.
The specific code is as follows,
Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs,
System.Data.SqlClient,
System.Data, System.ComponentModel, Borland.Vcl.StdCtrls,
Borland.Vcl.ExtCtrls, Borland.Vcl.DBCtrls, Borland.Vcl.Grids,
Borland.Vcl.DBGrids, Borland.Vcl.Db, Borland.Vcl.ADONETDb;
Type
TForm1 = Class (Tform)
Button1:tbutton;
Adonetconnector1:tadonetconnector;
Datasource1:tdatasource;
Dbgrid1:tdbgrid;
Dbnavigator1:tdbnavigator;
Procedure Button1Click (Sender:tobject);
Private
{Private declarations}
Connection:sqlconnection;
Prodataset:dataset;
Adapter:sqldataadapter;
Public
{Public declarations}
End
Var
Form1:tform1;
Implementation
{$R *.NFM}
Procedure Tform1.button1click (Sender:tobject);
Begin
Connection: = Sqlconnection.create (' ...) ');
Connection.Open;
Prodataset: = dataset.create;
Adapter: = Sqldataadapter.create (' select * from Product ', Connection);
Adapter.fill (Prodataset, ' Product ');
Adonetconnector1.datatable:=prodataset.tables[0];
End
End.