When creating a form for all datasets, I make an assignment of the type:

qNotfixrecg.Connection:=Fmain.FDConnection1; qfirmname.Connection:=Fmain.FDConnection1; qrecs.Connection:=Fmain.FDConnection1; qSett.Connection:=Fmain.FDConnection1; qpassw.Connection:=Fmain.FDConnection1; qnashti.Connection:=Fmain.FDConnection1; qprgExcel.Connection:=Fmain.FDConnection1; qStatus.Connection:=Fmain.FDConnection1; qService_user.Connection:=Fmain.FDConnection1; qShortvada.Connection:=Fmain.FDConnection1; qService_user.Connection:=Fmain.FDConnection1; qDocType.Connection:=Fmain.FDConnection1; qVatPayable.Connection:=Fmain.FDConnection1; qImp.Connection:=Fmain.FDConnection1; qUnits.Connection:=Fmain.FDConnection1; qFacts.Connection:=Fmain.FDConnection1; qPartn.Connection:=Fmain.FDConnection1; 

As it is possible to write the same thing most compactly in a loop, get a list of datasets (TFDQuery, TFDTable) and do an assignment in a loop.

  • There are no FDQuery and FDTable classes in Delfe. Probably meant TFDQuery and TFDTable (docwiki.embarcadero.com/Libraries/Tokyo/en/…) - Kromster
  • components from the components palette on the Firedac page - Delphi159
  • That's right, on the palette, the elements are called Button , and when added to a form it is Button1: TButton as objects and the class is Button1: TButton . - Kromster
  • Yes of course. Classes meant. Corrected. - Delphi159

1 answer 1

 for i := 0 to ComponentCount - 1 do begin if Components[i] is <базовый класс со свойством `.Connection`> then begin (Components[i] as <базовый класс со свойством `.Connection`>).Connection := Fmain.FDConnection1; end; end; 

or

 for i := 0 to ComponentCount - 1 do begin if Components[i] is TFDCustomQuery then begin (Components[i] as TFDCustomQuery).Connection := Fmain.FDConnection1; end; end; 
  • one
    TFDQuery and TFDTable are descendants of TFDCustomQuery. Therefore, you can simplify the second example to for i: = 0 to ComponentCount -1 do if Components [i] .InheristFrom (TFDCustomQuery) then (Components [i] as TFDCustomQuery) .Connection: = Fmain. FDConnection1; - dr. FIN