Custom Attributes and Interfaces
Delphi syntax dictates that the GUID (if present) must immediately follow the declaration of an interface. Since the
GUID syntax is similar to that of custom attributes, the compiler must be made to know the difference between a
custom attribute - which applies to the next declaration - and a GUID specifier, which applies to the previous
declaration. Without this special case, the compiler would try to apply an attribute to the first member of the interface.
When the compiler sees an interface declaration, the next square bracket construct found is assumed to be that of
a GUID specifier for the interface. The GUID must be in the traditional Delphi form:
['{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}']
Alternatively, you can use the
Guid
custom attribute of the .NET framework ( GuidAttribute). If you choose this
method, then you should introduce the attribute before the interface, as with any other custom attribute.
The effect in either case is the same: the GUID is emitted into the metadata for the interface type. Note that GUIDs
are not required for interfaces in the .NET Framework. They are only used for COM interoperability.
Note:
When importing COM interfaces with the
ComImport
custom attribute, you must declare the
GuidAttribute
instead of using the Delphi syntax.
247
Index
array properties
properties, 152
assembler syntax
inline assembler, 227
assembly expression
inline assembler, 233
assembly procedures and functions
inline assembler, 242
blocks
scope, 45
calling procedures and functions
procedures and functions, 128
character set
Delphi character set, 25
character set (Delphi)
reserved words, 25
classes and objects, 132
class fields
fields, 138
class properties
properties, 156
class references
classes and objects, 157
class types
classes and objects, 132
clauses
program structure, 13
constants
data types, 104
constructors
methods, 146
custom attributes, 245
data types, variables, and constants, 60
declarations and statements
statements, 30
declaring types
data types, 100
default parameters
parameters, 125
Delphi Language Overview
Overview, 7
directives
compiler directives, 29
dynamically loaded libraries
libraries, 181
exceptions
classes and objects, 160
expressions
operators, 48
fields
classes and objects, 138
foward declarations
classes and objects, 137
if statements
with statements, 33
index specifiers
properties, 153
inline assembler, 226
inline directive, 129
Interfaces
GUID, 192
libraries
initialization code, 183
libraries and packages, 179
memory management, 205
memory management on .NET, 216
methods
classes and objects, 140
namespaces
searching namespaces, 20
programs and units, 20
Nested Constants
Nested Types, 168
nested types
classes and objects, 167
object interfaces
interfaces, 191
open arrays, 128
operators
classes and objects, 158
overloading methods
methods, 145
packages, 186
parameters
procedures and functions, 119
pointer types
data types, 87
procedural types
data types, 90
procedures and functions, 110
program control, 221
program organization
programs and units, 13
program sections
interface section, 14
properties
classes and objects, 150
property access, 150
property overrides
248
properties, 154
simple types
data types, 62
standard routines, 170
statements, 31
simple statements, 31
storage specifiers
properties, 154
string types
data types, 70
structured types
data types, 76
syntax
symbols, special, 25
type compatibility
data types, 97
unit names
unit aliases, 22
uses clause
unit references, 16
variables
data types, 102
variant types
data types, 93
visibility
classes and objects, 135
249
Dostları ilə paylaş: |