I just found this in a TForm, that is used as a DataModule
I just found this in a TForm, that is used as a DataModule
procedure Tvars.FormDestroy(Sender: TObject);
begin
IBDatabase1.destroy;
IBTransaction1.destroy;
IBQuery1.destroy;
DataSource1.destroy;
IBQuery2.destroy;
DataSource2.destroy;
IBQuery3.destroy;
...
end;
this goes on for about 50 of the Non-Visual components that are dropped on this form.
Why would someone do this?
procedure Tvars.FormDestroy(Sender: TObject);
begin
IBDatabase1.destroy;
IBTransaction1.destroy;
IBQuery1.destroy;
DataSource1.destroy;
IBQuery2.destroy;
DataSource2.destroy;
IBQuery3.destroy;
...
end;
this goes on for about 50 of the Non-Visual components that are dropped on this form.
Why would someone do this?
Too much time?
ReplyDeleteAnd why .destroy instead of .Free.
ReplyDeleteThey could have done that with a for x:= to componentCount-1 and just destroy or free the IB components
ReplyDeleteBecause you can. ;-)
ReplyDeleteMaybe in earlier version all these components was created at runtime.
ReplyDeletePaid by line of code?
ReplyDeleteMy answer is: because the developer doesn't understand Delphi's component model. They don't get that those components will be freed naturally by the form (i.e., owner). In fact, I'm surprised it doesn't cause an access violation.
ReplyDeleteThe only way this makes sense is if those components are manually created and not parented/owned by the form.
He's not using Nick's FreeAndNil from what I see. ;)
ReplyDeleteFYI: all components are defined in the DFM and the form is created normally in the dpr with Application.CreateForm and there is no access violation on application exit.
ReplyDeleteI have a feeling that I'll get more of these kind of "anti-patterns" from this project. :-)