DataModuleDestroy overboard?

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
duzenbury
Fresh Boarder
Fresh Boarder
Posts: 4
Joined: 13.08.2009, 21:23

DataModuleDestroy overboard?

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
Post Reply