unit Divide2Numbers;

interface

uses
  Windows, Messages, SysUtils, Classes, Math;

type
  TDivide = class(TComponent)
  private
    { Private declarations }
    FNumber1: Extended;
    FNumber2: Extended;
    FResult:  Extended;
    FZeroDivide: TNotifyEvent;
  protected
    { Protected declarations }
  public
    { Public declarations }
    Constructor Create(AOwner: TComponent);override;
    property Result: Extended read FResult;
    //Result służy jedynie do odczytu wyniku
    //zmiennopozycyjnego dzielenia,
    //dlatego nie używamy tu słowa write
    procedure Divide2Numbers;
  published
    { Published declarations }
    property Number1: Extended read FNumber1 write FNumber1;
    property Number2: Extended read FNumber2 write FNumber2;
    property OnZeroDivide: TNotifyEvent read FZeroDivide
                                        write FZeroDivide;

  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TDivide]);
end;
//---------------------------------------------------------
Constructor TDivide.Create(AOwner: TComponent);
begin
  inherited Create(Aowner);
  FNumber1:=1;
  FNumber2:=1;
end;
//---------------------------------------------------------
procedure TDivide.Divide2Numbers;
begin
  if Number2 <> 0 then
    FResult:= FNumber1/FNumber2
    else
      if assigned(FZeroDivide) then OnZeroDivide(Self);
end;
end.

