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


The Finalize method is called asynchronously (both for objects, and for units). 2



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə261/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   257   258   259   260   261   262   263   264   ...   294
DelphiLanguageGuide

1
The Finalize method is called asynchronously (both for objects, and for units).
2
Finalization and destructors are used to free unmanaged resources such as file handles. You do not need to
destroy object member variables; the garbage collector takes care of this for you.
3
Classes should rely on the compiler's implementation of IDisposable, and provide a destructor called 
Destroy
.
4
If a class implements IDisposable itself, it cannot have a destructor called 
Destroy
.
5
Reference counting is deprecated. Try to use the 
destructor Destroy; override;
 pattern wherever
possible.
6
Unit initialization should not depend on side effects produced by initialization of dependent units.
Unit Initialization Considerations for Assemblies and Dynamically Linked Packages
Under Win32, the Delphi compiler uses the 
DllMain
 function as a hook from which to execute unit initialization
code. No such execution path exists in the .NET environment. Fortunately, other means of implementing unit
initialization exist in the .NET Framework. However, the differences in the implementation between Win32 and .NET
could impact the order of unit initialization in your application.
The Delphi for .NET compiler uses CLS-compliant class constructors to implement unit initialization hooks. The CLR
requires that every object type have a class constructor. These constructors, or type initializers, are guaranteed to
be executed at most one time. Class constructors are executed at most one time, because in order for the type to
be loaded, it must be used. That is, the assembly containing a type will not be loaded until the type is actually used
at runtime. If the assembly is never loaded, its unit initialization section will never run.
Circular unit references also impact the unit initialization process. If unit A uses unit B, and unit B then uses unit A
in its implementation section, the order of unit initialization is undefined. To fully understand the possibilities, it is
helpful to look at the process one step at a time.
1
Unit A's initialization section uses a type from unit B. If this is the first reference to the type, the CLR will load its
assembly, triggering the unit initialization of unit B.
2
As a consequence, loading and initializing unit B occurs before unit A's initialization section has completed
execution. Note this is a change from how unit initialization works under Win32.
218


3
Suppose that unit B's initialization is in progress, and that a type from unit A is used. Unit A has not completed
initialization, and such a reference could cause an access violation.
The unit initialization should only use types defined within that unit. Using types from outside the unit will impact unit
initialization, and could cause an access violation, as noted above.
Unit initialization for DLLs happens automatically; it is triggered when a type within the DLL is referenced. Applications
created with other .NET languages can use Delphi for .NET assemblies without concern for the details of unit
initialization.
219


Program Control
This section describes how parameters are passed to procedures and functions.
220


Program Control
The concepts of passing parameters and function result processing are important to understand before you
undertake your application projects Treatment of parameters and function results is determined by several factors,
including calling conventions, parameter semantics, and the type and size of the value being passed.
This following topics are covered in this material:
Passing Parameters.
Handling Function Results.
Handling Method Calls.
Understanding Exit Procedures.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   257   258   259   260   261   262   263   264   ...   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