FireDAC内部初探

时间:2022-09-02 05:35:17
procedure TForm1.Button1Click(Sender: TObject);
var
FCommIntf: IFDPhysCommand; //FireDAC.Phys.Intf
FTab: TFDDatSTable; //FireDAC.DatS
begin
FTab := TFDDatSTable.Create;
FDConnection1.ConnectionIntf.CreateCommand(FCommIntf);
FCommIntf.CommandText := 'select * from zfxx';
//FCommIntf.Prepare('select * from tjzfdb.dbo.zfxx');
FCommIntf.Define(FTab);
//FCommIntf.Open;
FCommIntf.Fetch(FTab); Caption := FTab.Rows.Count.ToString();
end; procedure TForm1.Button2Click(Sender: TObject);
var
oCommIntf: IFDPhysCommand;
oSchAdapt: IFDDAptSchemaAdapter;
oAdapt: IFDDAptTableAdapter; //FireDAC.DApt.Intf U
begin
{
uses
FireDAC.Stan.Factory, FireDAC.DApt;
}
//FDCreateInterface(IFDDAptSchemaAdapter, oSchAdapt);
//oAdapt := oSchAdapt.TableAdapters.Add;
//上面的2步可以用下面一行代码代替
FDCreateInterface(IFDDAptTableAdapter, oAdapt);
FDConnection1.ConnectionIntf.CreateCommand(oCommIntf);
if oAdapt.SelectCommand=nil then
oAdapt.SelectCommand := oCommIntf;
oCommIntf.CommandText := 'select * from zfxx';
oAdapt.Define;
oAdapt.Fetch(True);
Caption := oAdapt.DatSTable.Rows.Count.ToString();
end;

基本上是从DEMO上照搬的,初步理解内部情况。