How should you safely create and free multiple objects?
Basically, this sort of thing:
newOrderSource := TWebNewOrderSource.Create();
twData := T
You can do this with one try block if you assign nil to the variables first like,
newOrderSource := nil;
twData := nil;
webData := nil;
try
newOrderSource := TWebNewOrderSource.Create();
twData := TTWData.Create();
webData := TWebData.Create();
//do stuff
finally
webData.Free();
twData.Free();
newOrderSource.Free();
end;
This works because Free()
checks Self
for nil
.