In delphi.net, VCL.net has two regrets:
1. ADO (dbGo) cannot be used, but according to Levi, this component will be available in the future.
2. ADO.net and BDP cannot be used, which will be the theme of this article.
In Borland's delphi communication area, I once saw Danny say, "In delphi.net, VCL.net can call Winform components, and Winform can also call VCL.net components."
In order to verify the first sentence, I tried it. You can use .Net components in Vcl.net. For example, you can directly use System.Data.SqlClient and directly use the SqlConnection class. In other words, although .net components cannot be seen in the component panel of VCL.net, all .net component classes can be used by VCl.net! However, Ado.net's dataset is not compatible with VCl.net's Dataset component, so the data-aware component cannot be called directly. However, after reading Levi's Inside Vcl, I learned that there is an ADONETConnector component. Using this component, Ado.net can support the use of data-aware components.
First, the dll of the VCL.net component has a Borland.Vcl.Design.AdoNet.dll under BDS/2.0/Bin. Click the Install .net component menu, and then add this dll in the .net vcl components page of the form. After a click, you can see the ADONETConnector component. Then add a Dbgrid, db...., datasoure...., as long as datasource.dataset:=ADONETConnector1. The rest is the same as the original Delphi, and that's it. The same modification method is also effective for BDP.
My 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.