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ə168/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   164   165   166   167   168   169   170   171   ...   294
DelphiLanguageGuide

Overloading Methods
A method can be redeclared using the overload directive. In this case, if the redeclared method has a different
parameter signature from its ancestor, it overloads the inherited method without hiding it. Calling the method in a
descendant class activates whichever implementation matches the parameters in the call.
If you overload a virtual method, use the reintroduce directive when you redeclare it in descendant classes. For
example,
type 
  T1 = class(TObject) 
    procedure Test(I: Integer); overload; virtual;
  end; 
  T2 = class(T1) 
    procedure Test(S: string); reintroduce; overload; 
  end; 
  ... 
SomeObject := T2.Create; 
SomeObject.Test('Hello!');       // calls T2.Test 
SomeObject.Test(7);              // calls T1.Test
Within a class, you cannot publish multiple overloaded methods with the same name. Maintenance of runtime type
information requires a unique name for each published member.
type 
    TSomeClass = class 
      published 
145


        function Func(P: Integer): Integer; 
        function Func(P: Boolean): Integer;   // error 
          ...
Methods that serve as property read or write specifiers cannot be overloaded.
The implementation of an overloaded method must repeat the parameter list from the class declaration. For more
information about overloading, see Overloading procedures and functions.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   164   165   166   167   168   169   170   171   ...   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