In delphi.net, VCL.net has two regrets:
1. ADO (dbGo) cannot be used, but according to Li Wei, this month's delphi8.1 will have this component.
2. You cannot use ADO.net and BDP, this will be the topic of my article.
In the delphi communication area of Borland, Danny once said, "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. In Vcl.net, you can use .Net components, such as using System.Data.SqlClient directly, and using the SqlConnection class directly. In other words, although the .net component cannot be seen in the VCL.net component panel, all .net component classes, VCl.net, can be used! 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 looking at Li Wei's Inside Vcl, I found out that there was an ADONETConnector component. Using this component can enable Ado.net to 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. You can see the ADONETConnector component. Then add a Dbgrid, db..., datasource..., as long as datasource.dataset:=ADONETConnector1. The others are the same as the original delphi, just do it. 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(
'data source= 192.168.76.170;'+
'initial catalog=SfiecErp;'+
'passWord=qwert;'+
'persist security info=True;'+
'user id=sa;'+
'packet size=4096;'+
'Connection Lifetime=0;'+
'Connection Reset=False;'+
'Pooling=False;'+
'Max Pool Size=100;Min Pool Size=0');
Connection.Open;
ProDataSet := DataSet.Create;
Adapter := SqlDataAdapter.Create('select * from TProduct', Connection);
Adapter.Fill(ProDataSet, 'Product');
ADONETConnector1.DataTable:=ProDataSet.Tables[0];
end;
end.
In delphi.net, VCL.net has two regrets:
1. ADO (dbGo) cannot be used, but according to Li Wei, this month's delphi8.1 will have this component.
2. You cannot use ADO.net and BDP, this will be the topic of my article.
In the delphi communication area of Borland, Danny once said, "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. In Vcl.net, you can use .Net components, such as using System.Data.SqlClient directly, and using the SqlConnection class directly. In other words, although the .net component cannot be seen in the VCL.net component panel, all .net component classes, VCl.net, can be used! 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 looking at Li Wei's Inside Vcl, I found out that there was an ADONETConnector component. Using this component can enable Ado.net to 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. You can see the ADONETConnector component. Then add a Dbgrid, db..., datasource..., as long as datasource.dataset:=ADONETConnector1. The others are the same as the original delphi, just do it. 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(
'data source= 192.168.76.170;'+
'initial catalog=SfiecErp;'+
'password=qwert;'+
'persist security info=True;'+
'user id=sa;'+
'packet size=4096;'+
'Connection Lifetime=0;'+
'Connection Reset=False;'+
'Pooling=False;'+
'Max Pool Size=100;Min Pool Size=0');
Connection.Open;
ProDataSet := DataSet.Create;
Adapter := SqlDataAdapter.Create('select * from TProduct', Connection);
Adapter.Fill(ProDataSet, 'Product');
ADONETConnector1.DataTable:=ProDataSet.Tables[0];
end;
end.