回顾:TClientDataset "Missing data provider or data packet"

Revisited: TClientDataset "Missing data provider or data packet"

使用动态创建的 TFDQueryTClientDataSetTDataSetProvider 我遇到了“缺少数据提供者或数据包”的代码:

procedure ResetSavedPasswords(ADataModuleDataBaseAdmin : TDataModuleDataBaseAdmin);
var
   lQuery     : TFDQuery;
   lCDS       : TClientDataSet;
   lProvider  : TDataSetProvider;
begin
   lFrmBezig := TFormBezig.Create(nil);
   lQuery    := TFDQuery.Create(nil);
   lProvider := TDataSetProvider.Create(Application); 
   lCDS      := TClientDataSet.Create(nil);
   try
      lQuery.Connection := ADataModuleDataBaseAdmin.FDConnectionTimeTell;
      lQuery.CachedUpdates := true;
      lProvider.Options := lProvider.Options - [poUseQuoteChar];
      lProvider.DataSet := lQuery;
      lProvider.Name    := 'prvResetSavedPW';
      lCDS.ProviderName := lProvider.Name;
      lQuery.SQL.Text   := Format('select %s,%s from <owner>%s',[sMedMedID,sMedSavedPassword,SMedTabelNaam]),ADataModuleDataBaseAdmin;
      lCDS.Open;

请注意,创建的 TDataSetProvider 有一个所有者,基于 :

If DatasetProvider has no owner, ClientDataSet can not obtain a reference to the provider

但我仍然得到错误。打开 TFDQuery 首先显示它有数据。

可能是什么原因?

将 FireDAC 与 Delphi 10.4 结合使用。 Win32 应用程序中的悉尼。

原来TClientDataSet也需要主人:

lCDS := TClientDataSet.Create(Application);

从触发异常的代码中可以明显看出:

function TCustomClientDataSet.GetAppServer: IAppServer;
var
  ProvComp: TComponent;
  DS: TObject;
begin
  if not HasAppServer then
  begin
    if ProviderName <> '' then
      if Assigned(RemoteServer) then
        FAppServer := RemoteServer.GetServer
      else if Assigned(ConnectionBroker) then
        FAppServer := ConnectionBroker.GetServer
      else
      begin
        if Assigned(Owner) then
        begin
          ProvComp := Owner.FindComponent(ProviderName);
          if Assigned(ProvComp) and (ProvComp is TCustomProvider) then
          begin
            DS := GetObjectProperty(ProvComp, 'DataSet');
            if Assigned(DS) and (DS = Self) then
              DatabaseError(SNoCircularReference, Self);
            FAppServer := TLocalAppServer.Create(TCustomProvider(ProvComp));
          end;
        end;
      end;
    if not HasAppServer then
      DatabaseError(SNoDataProvider, Self);
  end;
  Result := FAppServer;
end;

Assigned(Owner) 失败,因此代码不会费心寻找 TDataSetProvider