Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə151/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   147   148   149   150   151   152   153   154   ...   294
DelphiLanguageGuide

TObject and TClass
The TObject class, declared in the 
System
 unit, is the ultimate ancestor of all other classes. TObject defines only
a handful of methods, including a basic constructor and destructor. In addition to TObject, the 
System
 unit declares
the class reference type TClass:
TClass = class of TObject;
If the declaration of a class type doesn't specify an ancestor, the class inherits directly from TObject. Thus
type TMyClass = class
      ... 
     end;
is equivalent to
type TMyClass = class(TObject) 
      ... 
     end;
The latter form is recommended for readability.
Compatibility of Class Types
A class type is assignment-compatible with its ancestors. Hence a variable of a class type can reference an instance
of any descendant type. For example, given the declarations
type 
     TFigure = class(TObject); 
     TRectangle = class(TFigure); 
     TSquare = class(TRectangle); 
var 
     Fig: TFigure;
the variable 
Fig
 can be assigned values of type 
TFigure

TRectangle
, and 
TSquare
.
Object Types
The Win32 Delphi compiler allows an alternative syntax to class types, which 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.
134


Object types are supported for backward compatibility only. Their use is not recommended on Win32, and they have
been completely deprecated in the Delphi for .NET compiler.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   147   148   149   150   151   152   153   154   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin