Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Komponente nur einmal pro Form/Projekt? (https://www.delphipraxis.net/79669-komponente-nur-einmal-pro-form-projekt.html)

DevilsCamp 26. Okt 2006 10:25


Komponente nur einmal pro Form/Projekt?
 
Hallo,
Gibt es eine Möglichkeit eine Komponente nur einmal pro Form/Projekt zuzulassen?

Beispiel:
Es macht sicher keinen Sinn die Komponente XPManifest mehr als einmal pro Projekt hinzuzufügen.

chaosben 26. Okt 2006 10:51

Re: Komponente nur einmal pro Form/Projekt?
 
Du könntest im Konstruktor alle Kind-Komponenten von deinem Parent durchgehen und prüfen ob sie der gesuchten Klasse entsprechen. Wenn du eine findest, wirfst du eine Exception.

DevilsCamp 26. Okt 2006 10:56

Re: Komponente nur einmal pro Form/Projekt?
 
Und dann?
Wie soll ich im Konstruktor dann das Objekt wieder freigeben?

hoika 26. Okt 2006 10:58

Re: Komponente nur einmal pro Form/Projekt?
 
Hallo,

warum packst du die nicht in das MainForm rein ?

Falls es sich um ein "NichtForm"-Komponente handelt,
könnte an das auch über singleton pattern lösen.

Was macht die denn konkret ?

Heiko

hoika 26. Okt 2006 11:00

Re: Komponente nur einmal pro Form/Projekt?
 
Hallo,

im constructor musst du VOR dem
inherited Create deinen Test machen.
Falls die schon im form dirn ist, erzeugst du eine Exception (raise Exception.Create).

Die Exception sorgt dafür, dass die Klasse freigegeben wird,
der destructor wird aufgerufen !

Einfach mal ausprobieren. (breakpoint auf den destructor)


Heiko


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:39 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz