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ə222/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   218   219   220   221   222   223   224   225   ...   294
DelphiLanguageGuide

Object Interfaces
This section describes the use of interfaces in Delphi.
190


Object Interfaces
An object interface, or simply interface, defines methods that can be implemented by a class. Interfaces are declared
like classes, but cannot be directly instantiated and do not have their own method definitions. Rather, it is the
responsibility of any class that supports an interface to provide implementations for the interface's methods. A
variable of an interface type can reference an object whose class implements that interface; however, only methods
declared in the interface can be called using such a variable.
Interfaces offer some of the advantages of multiple inheritance without the semantic difficulties. They are also
essential for using distributed object models (such as CORBA and SOAP). Using a distributed object model, custom
objects that support interfaces can interact with objects written in C++, Java, and other languages.
Interface Types
Interfaces, like classes, can be declared only in the outermost scope of a program or unit, not in a procedure or
function declaration. An interface type declaration has the form
type interfaceName = interface (ancestorInterface)
        ['{GUID}']
        memberList
end;
where (ancestorInterface) and ['{GUID}'] are optional. In most respects, interface declarations resemble class
declarations, but the following restrictions apply.
The memberList can include only methods and properties. Fields are not allowed in interfaces.
Since an interface has no fields, property read and write specifiers must be methods.
All members of an interface are public. Visibility specifiers and storage specifiers are not allowed. (But an array
property can be declared as default.)
Interfaces have no constructors or destructors. They cannot be instantiated, except through classes that
implement their methods.
Methods cannot be declared as virtual, dynamic, abstract, or override. Since interfaces do not implement their
own methods, these designations have no meaning.
Here is an example of an interface declaration:
type
IMalloc = interface(IInterface)
        ['{00000002-0000-0000-C000-000000000046}']
        function Alloc(Size: Integer): Pointer; stdcall;
        function Realloc(P: Pointer; Size: Integer): Pointer; stdcall;
        procedure Free(P: Pointer); stdcall;    
        function GetSize(P: Pointer): Integer; stdcall;
        function DidAlloc(P: Pointer): Integer; stdcall;
        procedure HeapMinimize; stdcall;
end;
In some interface declarations, the interface reserved word is replaced by dispinterface. This construction (along
with the dispid, read only, and write only directives) is platform-specific and is not used in Linux programming.
191



Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   218   219   220   221   222   223   224   225   ...   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