Ver Mensaje Individual
  #10  
Antiguo 26-03-2023
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Cita:
... estoy intentando de todo para abrir y cerrar los formulario pero me da error. cual es la sentencia correcta para abrir y cerra un formulario que no esta en autocreate?
Básicamente tienes que ejecutar la sentencias
Código Delphi [-]
Formulario := TFormulario.Create(Self);
Transcribo a continuación la ayuda de Delphi 6.

Creating forms dynamically
You may not always want all your application’s forms in memory at once. To reduce the amount of memory required at load time, you may want to create some forms only when you need to use them. For example, a dialog box needs to be in memory only during the time a user interacts with it.
To create a form at a different stage during execution using the IDE, you:
  1. Select the File|New Form from the main menu to display the new form.
  2. Remove the form from the Auto-create forms list of the Project|Options|Forms page.
    This removes the form’s invocation. As an alternative, you can manually remove the following line from program’s main entry point:
    Application.CreateForm(TResultsForm, ResultsForm);
  3. Invoke the form when desired by using the form’s Show method, if the form is modeless, or ShowModal method, if the form is modal.
An event handler for the main form must create an instance of the result form and destroy it. One way to invoke the result form is to use the global variable as follows. Note that ResultsForm is a modal form so the handler uses the ShowModal method.

Código Delphi [-]
procedure TMainForm.Button1Click(Sender: TObject);
begin
ResultsForm:=TResultForm.Create(self);
try
  ResultsForm.ShowModal;
finally
  ResultsForm.Free;
end;
In the above example, note the use of try..finally. Putting in the line ResultsForm.Free; in the finally clause ensures that the memory for the form is freed even if the form raises an exception.
The event handler in the example deletes the form after it is closed, so the form would need to be recreated if you needed to use ResultsForm elsewhere in the application. If the form were displayed using Show you could not delete the form within the event handler because Show returns while the form is still open.

Note: If you create a form using its constructor, be sure to check that the form is not in the Auto-create forms list on the Project Options|Forms page. Specifically, if you create the new form without deleting the form of the same name from the list, Delphi creates the form at startup and this event-handler creates a new instance of the form, overwriting the reference to the auto-created instance. The auto-created instance still exists, but the application can no longer access it. After the event-handler terminates, the global variable no longer points to a valid form. Any attempt to use the global variable will likely crash the application.


En el caso de que quieras mostrar un formulario con ShowModal puedes envolver todo en un try..finally
En el caso de mostrarlo con Show no debes hacerlo porque estarías eliminándolo inmediatamente después de crearlo.
En ese caso debes crearlo y dejar que el formulario en su evento OnClose establezca la acción caFree;

Código Delphi [-]
procedure TFormulario.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;
Responder Con Cita