Placing the Difference Between Forms Construction Methods in Delphi
1 - Application.CreateForm(TForm, Form);
Creates a global scope variable that can be instantiated in any other form, of course with the previous addition of the Unit in the form where you want to use it, example roughly:
Application.CreateForm(TFormCliente, FormCliente);
Application.CreateForm(TFormDetalhes, FormDetalhes);
Application.CreateForm(TFormSubDetalhes, FormSubDetalhes);
FormDetalhes.SubShowModal;
... rotina ...
Aqui estará disponpivel o formulário FormCliente e FormDetalhes
... Aguarda FormSubDetalhes ser fechado para continuar
FormDetalhes.ShowModal;
Idem
FormCliente.ShowModal;
In this case the Formclient form would be available in the other two created later ( provided that added to Unit Formclient in USES )
2 - Form := Tform.Create(Application);
Even saying that the owner is Application it will not be available in a call from a Showmodal form subsequent to it, example roughly:
FormCliente := TFormCliente.Create(Application);
FormDetalhes := TFormDetalhes.Create(Application);
FormSubDetalhes := TFormSubDetalhes.Create(Application);
FormDetalhes.SubShowModal;
... rotina ...
Aqui não estará disponpivel o formulário FormCliente nem FormDetalhes
... Aguarda FormSubDetalhes ser fechado para continuar
FormDetalhes.ShowModal;
Idem
FormCliente.ShowModal;
Form := Tform.Create(Application); Creates a local variable, so trying to use the form in other Units will give the Accessviolation error, because the form (variable) was not created globally
Another way of understanding:
Within a function we can create variables that will be of exclusive use of that function, example 1
function fTeste(): Integer;
var vlocal: Integer;
begin
result := vlocal+1;
end;
If you try to use the vlocal variable outside the function you will have an error because the variable was not created globally.
Example 2:
public // Declarando a variável para ser publica (global)
vpublica: Integer;
function fTeste(): Integer;
begin
result := vpublica+1;
end;
In example 2 the vpublica variable will be available in any part of the current form and any form you wish to use this Unit
Descriptive summary:
I confused the creation of the Form with the creation of the Form Variable, I explain, when creating the form we can say who owns the form, if the application or others, this is necessary to know for the moment of destruction of the application, for the correct release of memory, already the creation of the variable whether it will be global or local, will give you power to use it locally or globally, I thought that when we put "Application" the created form would be available in any and all part of the application.
I hope I was clear.
As far as I know there is no difference, it is simply different construction methods. About
não estará disponível para outros formulários
can explain this part better?– Junior Moreira
Even after researching and putting the question here I insisted on the answer and really have difference, Application.Createform Creates a global variable so the form is seen in any part of the application, already Tform.Create creates a variable inside the form where it was instantiated and is therefore not available in other instances generating the false impression that it is available in another form, I will answer this question and try to detail how it works.
– Marcelo
Reading your answer I understood your question, the part in the question:
não estará disponível para outros formulários
wasn’t so clear! Make an issue in the question and improve that part where you doubt it. + 1 by Reply.– Junior Moreira