The following code shows a component that defines two new methods, one protected method and one public virtual method.
This is the interface definition in the .H file:
class PACKAGE TSampleComponent : public TControl { protected: void __fastcall MakeBigger(); public: virtual int __fastcall CalculateArea(); . . . };
This is the code in the .CPP file of the unit that implements the methods:
void __fastcall TSampleComponent::MakeBigger() { Height = Height + 5; Width = Width + 5; } int __fastcall TSampleComponent::CalculateArea() { return Width * Height; }
type TSampleComponent = class(TControl) protected procedure MakeBigger; { declare protected static method } public function CalculateArea: Integer; virtual; { declare public virtual method } end; . . . implementation . . . procedure TSampleComponent.MakeBigger; { implement first method } begin Height := Height + 5; Width := Width + 5; end; function TSampleComponent.CalculateArea: Integer; { implement second method } begin Result := Width * Height; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|