|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
Разница между "class" "object"
Добрый день.
У меня чайниковский вопрос. В чем разница, с точки зрения компилятора и порядком работы программы, между следующими записями t = class private i: integer; public procedure set_i; end; и t = object private i: integer; public procedure set_i; end; ? Предыстория следующая. Есть библиотека (unit), в которой описан объект-класс "t", не содержащий визуальные компоненты. Экземпляр данного объекта-класса создается в форме которая описана отдельно. Так вот если "t" описан как object то, пока , никаких проблем не возникает. Если он описан как class то при выполнении метода set_i выводится сообщение (я пока не понял кто его выводит ), что не объявлена переменная i. В чем принципиальная разница между t = class и t = object? |
#2
|
||||
|
||||
Вот что написано в справке:
Код:
As an alternative to class types, you can declare object types using the syntax type objectTypeName = object (ancestorObjectType) memberList end; where objectTypeName is any valid identifier, (ancestorObjectType) is optional, and memberList declares fields, methods, and properties. If (ancestorObjectType) is omitted, then the new type has no ancestor. Object types cannot have published members. Since object types do not descend from TObject, they provide no built-in constructors, destructors, or other methods. You can create instances of an object type using the New procedure and destroy them with the Dispose procedure, or you can simply declare variables of an object type, just as you would with records. Object types are supported for backward compatibility only. Their use is not recommended. |