Differences in the dynamic creation of an object

Asked

Viewed 2,491 times

5

When I create an object dynamically, for example a form, I do so:

Formulario := TFormulario.Create(nil);  
try  
    Formulario.ShowModal;  
finally  
    Formulario.Free;  
end;  

What’s the difference in creating an object by passing the following values to the parameter Aowner in the method Create?

Formulario := TFormulario.Create(Application);  
Formulario := TFormulario.Create(nil);  
Formulario := TFormulario.Create(Self);  

1 answer

10


The difference is who is the "owner" of the window. That is, if the "owner" is displaced, all Forms who own this form as owner are also displaced.

  • In the first example, the form is only out of focus if the entire application is also. This is not much recommended for performance issues because the notifications you passed to Application take longer to be processed;
  • In the second, the form does not have owner, that is, the programmer should control the location of this form;
  • In the third, the form belongs to the screen that called it. Recommended for calling screen modals.
  • I don’t remember reading what to use Application influence performance. Source on this?

  • 5

    @Embarbosa Source: http://delphi.about.com/od/adptips2005/qt/nilselfapp.htm

  • Thank you. I think I should quote the sources in the reply. + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.