{************************************************}
{ TCCIFunction (Commodity Chanel Index)          }
{ Copyright (c) 2002-2020 by Steema Software     }
{ Portions Copyright (c) 2004-2020 Inverline.com }
{************************************************}
unit TeeCCIFunction;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,

  OHLChart, TeEngine, TeCanvas, Chart, TeeBaseFuncEdit, StatChar, ExtCtrls;

type
  TCCIFuncEditor = class(TBaseFunctionEditor)
    Label1: TLabel;
    EConst: TEdit;
    Label2: TLabel;
    EPeriod: TEdit;
    UDPeriod: TUpDown;
    procedure EConstChange(Sender: TObject);
    procedure EPeriodChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure ApplyFormChanges; override;
    Procedure SetFunction; override;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  TeeProCo, TeeProcs, TeeConst;

{ TCCIFuncEditor }
procedure TCCIFuncEditor.ApplyFormChanges;
begin
  inherited;

  with TCCIFunction(IFunction) do
  begin
    BeginUpdate;
    try
      Constant:=StrToFloatDef(EConst.Text,Constant);
      Period:=UDPeriod.Position;
    finally
      EndUpdate;
    end;
  end;
end;

procedure TCCIFuncEditor.SetFunction;
begin
  inherited;
  with TCCIFunction(IFunction) do
  begin
    EConst.Text:=FloatToStr(Constant);
    UDPeriod.Position:=Round(Period);
  end;
end;

procedure TCCIFuncEditor.EConstChange(Sender: TObject);
begin
  EnableApply;
end;

procedure TCCIFuncEditor.EPeriodChange(Sender: TObject);
begin
  EnableApply;
end;

procedure TCCIFuncEditor.FormCreate(Sender: TObject);
begin
  inherited;
  EConst.Text:=FloatToStr(0.015); // due to locale settings...
end;

initialization
  RegisterClass(TCCIFuncEditor);
end.
