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


Declaring a Custom Attribute Class



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə290/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   286   287   288   289   290   291   292   293   294
DelphiLanguageGuide

Declaring a Custom Attribute Class
Creating a custom attribute is the same as declaring a class. The custom attribute class has a constructor, and
properties to set and retrieve its state data. Custom attributes must inherit from TCustomAttribute. The following
code declares a custom attribute with a constructor and two properties:
    type
       TCustomCodeAttribute = class(TCustomAttribute)
          private
              Fprop1 : integer;
              Fprop2 : integer;
              aVal   : integer;
              procedure Setprop1(p1 : integer);
              procedure Setprop2(p2 : integer);
          public
              constructor Create(const myVal : integer);
              property prop1 : integer read Fprop1 write Setprop1;
              property prop2 : integer read Fprop2 write Setprop2;
       end;
The implementation of the constructor might look like
  constructor TCustomCodeAttribute.Create(const myVal : integer);
  begin
      inherited Create;
      aVal := myVal;
  end;
Delphi for .NET supports the creation of custom attribute classes, as shown above, and all of the custom attributes
provided by the .NET framework.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   286   287   288   289   290   291   292   293   294




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

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin