Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2007.06.17;
Скачать: [xml.tar.bz2];

Вниз

Наследование от базового класса.   Найти похожие ветки 

 
pathfinder ©   (2007-05-29 16:46) [0]

Здравствуйте.
Подскажите, пожалуйста, для чего при создании класса, наследуемого от TObject в конструкторе и деструкторе пишут inherited Create, inherited Destroy?


 
Jeer ©   (2007-05-29 16:48) [1]

чтобы эти самые inherited выполнились, если нужны конечно.


 
oxffff ©   (2007-05-29 16:48) [2]

The reserved word inherited plays a special role in implementing polymorphic behavior. It can occur in method definitions, with or without an identifier after it.

If inherited is followed by the name of a member, it represents a normal method call or reference to a property or field--except that the search for the referenced member begins with the immediate ancestor of the enclosing method"s class. For example, when

inherited Create(...);

occurs in the definition of a method, it calls the inherited Create.

When inherited has no identifier after it, it refers to the inherited method with the same name as the enclosing method or, if the enclosing method is a message handler, to the inherited message handler for the same message. In this case, inherited takes no explicit parameters, but passes to the inherited method the same parameters with which the enclosing method was called. For example,

inherited;

occurs frequently in the implementation of constructors. It calls the inherited constructor with the same parameters that were passed to the descendant.


 
pathfinder ©   (2007-05-29 16:49) [3]


> чтобы эти самые inherited выполнились, если нужны конечно.
>
>


Так ведь в классе TObject методы Create и Destroy пустые..


 
MBo ©   (2007-05-29 16:49) [4]

inherited Destroy- чтобы вызывался унаследованный деструктор
inherited Create - унаследованный конструктор. Для прямых наследников TObject родительский конструктор вызывать не обязательно, т.к. он ничего не делает


 
Однокамушкин   (2007-05-29 16:51) [5]


> pathfinder ©   (29.05.07 16:49) [3]
> Так ведь в классе TObject методы Create и Destroy пустые.

А в следующей версии Delphi вдруг будут не пустые... и ваш код станет некорректно работать...


 
oxffff ©   (2007-05-29 16:51) [6]


> pathfinder ©   (29.05.07 16:49) [3]
>
> > чтобы эти самые inherited выполнились, если нужны конечно.
>
> >
> >
>
>
> Так ведь в классе TObject методы Create и Destroy пустые.
> .


Можешь не писать, если от Tobject наследуешь


 
oxffff ©   (2007-05-29 16:52) [7]


>
> > pathfinder ©   (29.05.07 16:49) [3]
> > Так ведь в классе TObject методы Create и Destroy пустые.
>
>
> А в следующей версии Delphi вдруг будут не пустые... и ваш
> код станет некорректно работать...


Скорее NewInstance будут править. :)



Страницы: 1 вся ветка

Форум: "Начинающим";
Текущий архив: 2007.06.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.043 c
1-1177061372
Лысеющий Самурай
2007-04-20 13:29
2007.06.17
Как получить выделенный текст


4-1168175568
Чапаев
2007-01-07 16:12
2007.06.17
Права доступа


11-1162470019
Thaddy
2006-11-02 15:20
2007.06.17
FPC and koldef.inc


8-1159790519
Nickla
2006-10-02 16:01
2007.06.17
DSPack: ошибка при инициализации TSampleGraber как службу


1-1176899250
webpauk
2007-04-18 16:27
2007.06.17
размер иконок





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский