unit FMXTee.Editor.Functions.Base;

interface

uses
  System.SysUtils, System.Types, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Engine;

type
  TBaseFunctionEditor = class(TForm)
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private declarations }
  protected
    CreatingForm : Boolean;
    IFunction    : TTeeFunction;

    procedure ApplyFormChanges; virtual;  // dont make abstract (D5 bug)
    procedure EnableApply;
    procedure FillSeries(Items:TStrings);
    Procedure SetFunction; virtual;   // dont make abstract (D5 bug)
  public
    { Public declarations }
    procedure ActivateFunction; virtual;
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Functions, FMXTee.Chart;

procedure TBaseFunctionEditor.ApplyFormChanges;
begin
end;

procedure TBaseFunctionEditor.EnableApply;
begin
  if Assigned(Owner) then
     TFunctionEditor(Owner).BApply.Enabled:=True;
end;

procedure TBaseFunctionEditor.FillSeries(Items: TStrings);
begin
  if Assigned(IFunction.ParentSeries) and
     Assigned(IFunction.ParentSeries.ParentChart) then
       FillSeriesItems(Items,IFunction.ParentSeries.ParentChart.SeriesList);
end;

procedure TBaseFunctionEditor.ActivateFunction;
begin
  CreatingForm:=True;
  IFunction:=TTeeFunction(TagObject);

  if Assigned(IFunction) then
  begin
    SetFunction;

    if Assigned(Owner) then
       TFunctionEditor(Owner).BApply.Enabled:=False;
  end;

  CreatingForm:=False;
end;

procedure TBaseFunctionEditor.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);

  Function Series:TChartSeries;
  begin
    result:=TFunctionEditor(Owner).Series;
  end;

begin
  if not Assigned(IFunction) then
     IFunction:=CreateNewTeeFunction(Series,TFunctionEditor(Owner).FunctionClass);

  With IFunction do
  begin
    BeginUpdate;
    ApplyFormChanges;
    EndUpdate;
  end;

  if not Assigned(Series.FunctionType) then
     Series.SetFunction(IFunction);

  CanClose:=True;
end;

procedure TBaseFunctionEditor.SetFunction;
begin
end;

end.
