Sign in Join
Wiki copytemporary

Testing, if form exists/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Testing, if form exists/fr

OldNewLine
1+Parfois, une [[TForm/fr|fiche]] peut être lancée depuis plusieurs endroits dans un programme. Si elle existe déjà, il suffit de la placer en avant-plan, sinon elle doit être créée.
2+
3+La façon la plus simple est celle-ci :
4+```
5+if (MyForm = nil) then Application.CreateForm(TMyForm, MyForm);
6+ MyForm.Show;
7+```
8+
9+Utiliser `CloseAction := caFree;` dans l'événement OnClose de la fiche.
10+```
11+procedure TMyForm.Formclose(Sender: Tobject; var Closeaction: Tcloseaction);
12+ begin
13+ CloseAction := caFree;
14+ MyForm := nil;
15+ End;
16+```
17+
18+Cette méthode provient des discussions dans le forum.
19+
20+[![Warning-icon.png](/wiki-images/b/b2/Warning-icon.png)](</File:Warning-icon.png>)
21+
22+**Avertissement:** Cette méthode a des limitations :
23+
24+
25+ * A tout moment, il ne doit pas y avoir plus d'une instance de la classe de cette fiche (la variable MyForm devient incohérente sinon).
26+ * La référence à toute forme de cette classe devrait être enregistrée dans cette unique variable globale.
27+
28+---
29+*From the Free Pascal wiki, page "Testing, if form exists/fr", as the Internet Archive kept it on 2025-01-23, last changed on 2020-02-29. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history