Page 1 of 1

DataModuleDestroy overboard?

Posted: 13.08.2009, 21:32
by duzenbury
I'm maintaining an existing project, and I've run across this code, but I can't imagine why it might be necessary. Since the query components on the data module form are owned by the data module, wouldn't their destroy mechanisms automatically be called when the program ends, and thus in turn each active query would be closed? It is my thinking that this code is not necessary. Do you agree?

Code: Select all

procedure TDMGeneral.DataModuleDestroy(Sender: TObject);
var
    i : integer;
    s : String;
begin
   Try
       for i:=0 to ComponentCount-1 do
       begin
           if (Components[i] is tZQuery) then
           begin
               try
                  s:= Components[i].Name;
                  (Components[i] as tZQuery).Close;
               finally
                  s:= Components[i].Name;
               end;
           end
           else if (Components[i] is tZReadOnlyQuery) then
           begin
               try
                  s:= Components[i].Name;
                  (Components[i] as tZReadOnlyQuery).Close;
               finally
                  s:= Components[i].Name;
               end;
           end;
       end;
   Except
       Raise;
   End;
end;
Thank you.


Regards,
Rich

Posted: 25.08.2009, 21:44
by mdaems
Seems like unnecessary code indeed.

Maybe somebody was thinking it's just nicer to close queries yourself when you did also open them in your application?

Mark