Einzelnen Beitrag anzeigen

Benutzerbild von MaBuSE
MaBuSE

Registriert seit: 23. Sep 2002
Ort: Frankfurt am Main (in der Nähe)
1.837 Beiträge
 
Delphi 10 Seattle Enterprise
 
#11

Re: Warum kann man Vererbung verhindern (csInheritable)?

  Alt 25. Aug 2006, 09:59
Zitat von Der_Unwissende:
Zitat von MaBuSE:
ich habe mal eine grundsätzliche Frage:
Warum ist es möglich zu verhindern, dass ein Formular abgeleitet werden kann?
Hi,
ist eigentlich eine wirklich interessante Frage. Hab noch gar nicht drüber nachgedacht, dass Delphi ja auch diese Funktionalität bietet. An sich gibt es ja auch in anderen Sprachen die Möglichkeit eine Klasse nicht erweiterbar zu deklarieren. In Java wäre eine solche Klasse dann mit dem Schlüsselwort final versehen.
Nicht die Komponente ist final, sondern das Form, auf dem so eine Komponente liegt, die diese Eigenschaft hat!

Man packe eine TActionManager auf das Form und das Form ist nicht mehr vererbbar.

Man kann trotzdem noch von TActionManager ableiten.

Zitat von Jelly:
Also ich vermute, dass es verschiedene Komponenten gibt, die nur einmal pro Anwendung erlaubt sind, oder genutzt werden sollen (XPManifest, TDatabase usw.).

Grad bei TDatabase darf pro Anwendung nur eine TDatabase pro Datenbank definiert sein. Wenn Du jetzt aber von einer Form erbst, die eine TDatabase implementiert, so hast du zwangsläufig 2 identische Verbindungen.

Dieser Artikel bestätigt auch meinen Verdacht... Mann, bin ich gut
Im obigen Artikel steht
As a result of form inheritance being introduced in Delphi 2.0, the ComponentStyle property was added to the TComponent class. This property represents a set of style attributes that govern how a component behaves. In particular, the set can hold two possible styles: csInheritable and csCheckPropAvail.

The csInheritable style indicates that the component can be inherited by a descendent form type. For a form to be inheritable (that is, serve as an ancestor to another form), all components on the form must have the csInheritable style set. If any of the components do not include this style, then Delphi will display an error when you attempt to create a new form descendant. The TComponent class sets the csInheritable style by default in its constructor, and for most circumstances, you will not need to change it. However, it may be necessary to remove this style because of how the component is implemented. For example, the TDatabase component class removes this style because there can only be one Database component per database in an application. If this style is not removed, then a form and its ancestor could be used in the same application, thereby causing the Database component on each form to reference the same physical database.


Das ist aber definitiv falsch !!! Man sollte nicht alles glauben, was im Internet steht.
TDatabase auf ein TForm und ich kann es trotzdem vererben !!!
(Das habe ich gerade in D7 getestet.)
In Delphi 7 haben nur die 3 oben angegebenen Komponenten diese "Ich will nicht, dass mein OwnerForm vererbt wird" Eigenschaft implementiert.
Das kann es also nicht sein.

Auch kann ich mehrere TActionManager auf ein Formular legen.
Das kann es also auch nicht sein.

Selbst das XPManifest kannst du auf beliebige Formulare beliebig oft legen.
Diese Komponente ist nur ein Dummy.
Das Wichtige ist das {$R WindowsXP.res} in der XPMan Unit.
Und das wird nur einmal pro App eingebunden, da die Unit XPMan ja nur einmal in die App gelinkt wird.

Trotzdem Danke für Eure Gedanken

Hat jemand weitere Ideen (oder gar das Wissen) ?
(°¿°) MaBuSE - proud to be a DP member
(°¿°) MaBuSE - proud to be a "Rüsselmops" ;-)
  Mit Zitat antworten Zitat