Clientdataset

Delphi

09/03/2010

Boa tarde   Gostaria de Saber se existe algum comando para fechar todos os clientdataset do sistema. Por exemplo para colocar esse comando no onclose d um form e entao fechar todos datsets do sistema.   obrigado!!
Marcio Vergani

Marcio Vergani

Curtidas 0

Respostas

Jordelino Santos

Jordelino Santos

09/03/2010

Eu uso essa procedure abaixo:

procedure TLib001.prFechaComponentes(_rForm: TForm);
var
   _rintCount : Integer;
begin
   //No FormClose Lib001.prFechaComponentes(Formxxxxx);
   for _rintCount := 1 to Pred(_rForm.ComponentCount) do
   begin
      if _rForm.Components[_rintCount].ClassType = TClientDataSet then
      begin
         if not(TClientDataSet(_rForm.Components[_rintCount]).IsEmpty) then
         begin
            TClientDataSet(_rForm.Components[_rintCount]).EmptyDataSet;
         end;
      end;
      if _rForm.Components[_rintCount].ClassType = TQuery then
      begin
         TQuery(_rForm.Components[_rintCount]).Close;
      end;
   end;
end;
GOSTEI 0
Fábio Cruz

Fábio Cruz

09/03/2010

Boa tarde   Gostaria de Saber se existe algum comando para fechar todos os clientdataset do sistema. Por exemplo para colocar esse comando no onclose d um form e entao fechar todos datsets do sistema.   obrigado!!


Faz um FOR varrendo os componentes do form, se for ClientDataSet, fecha.

não tenho delphi aqui, mas acredito que seria basicamente isso:

  For I := 0 to Pred(ComponentsCount) do
  begin
    if (Components[I] is TClientDataSet) then
      (Components[I] as TClientDataSet).Close;
  end;

GOSTEI 0
POSTAR