Home HomeLEGO MINDSTORMS The Unofficial Guide to Robots Jonathan B. KnudsenNovell Netware 5 Advanced Admin Instructor guideHacking into computer systems a beginners guide (2)Cisco Press CCDA Study GuidePHP5 CMS Framework Development; Martin Brampton (McGraw Hill Osborne)MS XP Registry GuideLinux Users' GuideUser GuideBorland C Builder 6 BookChmielewska Joanna Duza polka
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • anna-weaslay.opx.pl
  •  

    [ Pobierz całość w formacie PDF ]
    .Note For these examples, the immediate base class or an ancestor class is assumed to haveimplemented the methods of IInterface, the base interface from which all interfacesdescend.For more information on IInterface, see  Implementing IInterface onpage 4-14 and  Memory management of interface objects on page 4-18.Using interfaces with proceduresInterfaces allow you to write generic procedures that can handle objects withoutrequiring that the objects descend from a particular base class.Using the IPaint andIRotate interfaces defined previously, you can write the following procedures:procedure PaintObjects(Painters: array of IPaint);varI: Integer;beginfor I := Low(Painters) to High(Painters) doPainters[I].Paint;end;procedure RotateObjects(Degrees: Integer; Rotaters: array of IRotate);varI: Integer;beginfor I := Low(Rotaters) to High(Rotaters) doRotaters[I].Rotate(Degrees);end;RotateObjects does not require that the objects know how to paint themselves andPaintObjects does not require the objects know how to rotate.This allows the genericprocedures to be used more often than if they were written to only work against aTFigure class.Implementing IInterfaceJust as all objects descend, directly or indirectly, from TObject, all interfaces derivefrom the IInterface interface.IInterface provides for dynamic querying and lifetimemanagement of the interface.This is established in the three IInterface methods:" QueryInterface dynamically queries a given object to obtain interface references forthe interfaces that the object supports." _AddRef is a reference counting method that increments the count each time a callto QueryInterface succeeds.While the reference count is nonzero the object mustremain in memory." _Release is used with _AddRef to allow an object to track its own lifetime anddetermine when it is safe to delete itself.Once the reference count reaches zero, theobject is freed from memory.4-14 Devel oper  s Gui de Us i n g i n t e r f a c e sEvery class that implements interfaces must implement the three IInterface methods,as well as all of the methods declared by any other ancestor interfaces, and all of themethods declared by the interface itself.You can, however, inherit theimplementations of methods of interfaces declared in your class.By implementing these methods yourself, you can provide an alternative means oflifetime management, disabling reference-counting.This is a powerful technique thatlets you decouple interfaces from reference-counting.TInterfacedObjectWhen defining a class that supports one or more interfaces, it is convenient to useTInterfacedObject as a base class because it implements the methods of IInterface.TInterfacedObject class is declared in the System unit as follows:typeTInterfacedObject = class(TObject, IInterface)protectedFRefCount: Integer;function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;function _AddRef: Integer; stdcall;function _Release: Integer; stdcall;publicprocedure AfterConstruction; override;procedure BeforeDestruction; override;class function NewInstance: TObject; override;property RefCount: Integer read FRefCount;end;Deriving directly from TInterfacedObject is straightforward.In the following exampledeclaration, TDerived is a direct descendant of TInterfacedObject and implements ahypothetical IPaint interface.typeTDerived = class(TInterfacedObject, IPaint)’end;Because it implements the methods of IInterface, TInterfacedObject automaticallyhandles reference counting and memory management of interfaced objects.For moreinformation, see  Memory management of interface objects on page 4-18, whichalso discusses writing your own classes that implement interfaces but that do notfollow the reference-counting mechanism inherent in TInterfacedObject.Us i ng t he obj ect model 4-15 Us i n g i n t e r f a c e sUsing the as operator with interfacesClasses that implement interfaces can use the as operator for dynamic binding on theinterface [ Pobierz caÅ‚ość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • syriusz777.pev.pl
  •