Mirror

How to open or close all datasets in on the form (Views: 100)


Problem/Question/Abstract:

How to open or close all datasets in on the form

Answer:

Open datasets: OpenDataSet(MyForm);

procedure OpenDataSet(FormName: TForm);
var
  I: Integer;
begin
  for I := FormName.ComponentCount - 1 downto 0 do
    if (FormName.Components[I] is TADOTable) then
    begin
      (FormName.Components[I] as TADOTable).Open;
    end;
end;

Close datasets: CloseDataSet(MyForm);

procedure CloseDataSet(FormName: TForm);
var
  I: Integer;
begin
  for I := FormName.ComponentCount - 1 downto 0 do
    if (FormName.Components[I] is TADOTable) then
    begin
      (FormName.Components[I] as TADOTable).Close;
    end;
end;

<< Back to main page