anchor.diff:    begin
       tmpNames := TStringList.Create;
       try
  -      FDataset.DisableControls;
  +      for i := 1 to FGrid.RowCount - 1 do
  +      begin
  +        tmpString := UpperCase(Trim(FGrid.Cells[IDX_NAME, i]));
  +        tmpNames.Add(tmpString);
  +
  +        tmpFormula := FFormulas.FindByName(tmpString);
  +        if not Assigned(tmpFormula) then
  +          tmpFormula := FFormulas.Add;
  +        tmpFormula.Name:= tmpString;
  +        if FGrid.Cells[IDX_TYPE, i] = 'DOUBLE' then
  +          tmpFormula.DataType:= fftFloat
  +        else if FGrid.Cells[IDX_TYPE, i] = 'DATE' then
  +          tmpFormula.DataType:= fftDateTime
  +        else
  +        begin
  +          tmpFormula.DataType:= fftString;
  +          tmpFormula.Size:= StrToInt(FGrid.Cells[IDX_SIZE, i]);
  +        end;
  +
  +        tmpFormula.Formula:= trim(FGrid.Cells[IDX_FORMULA, i]);
  +      end;
  +
  +      tmpToBeDeleted := TStringList.Create;
         try
  -        FDataset.First;
  -        while not FDataset.Eof do
  +        for i := 0 to FFormulas.Count - 1 do
           begin
  -          tmpString := UpperCase(Trim(FDataset.FieldByName('FldName').AsString));
  -          tmpNames.Add(tmpString);
  -
  -          tmpFormula := FFormulas.FindByName(tmpString);
  -          if not Assigned(tmpFormula) then
  -            tmpFormula := FFormulas.Add;
  -          tmpFormula.Name:= tmpString;
  -          if FDataset.FieldByName('FldType').AsString = 'DOUBLE' then
  -            tmpFormula.DataType:= fftFloat
  -          else if FDataset.FieldByName('FldType').AsString = 'DATE' then
  -            tmpFormula.DataType:= fftDateTime
  -          else
  -          begin
  -            tmpFormula.DataType:= fftString;
  -            tmpFormula.Size:= FDataset.FieldByName('FldSize').AsInteger;
  -          end;
  -
  -          tmpFormula.Formula:= trim(FDataset.FieldByName('FldFormula').AsString);
  -
  -          FDataset.Next;
  +          if tmpNames.IndexOf(FFormulas.Get(i).Name) < 0 then
  +            tmpToBeDeleted.Add(FFormulas.Get(i).Name);
           end;
  -
  -        tmpToBeDeleted := TStringList.Create;
  -        try
  -          for i := 0 to FFormulas.Count - 1 do
  -          begin
  -            if tmpNames.IndexOf(FFormulas.Get(i).Name) < 0 then
  -              tmpToBeDeleted.Add(FFormulas.Get(i).Name);
  -          end;
  -          for i := 0 to tmpToBeDeleted.Count - 1 do
  -          begin
  -            FFormulas.Delete(tmpToBeDeleted.Strings[i]);
  -          end;
  -
  -        finally
  -          tmpToBeDeleted.Free;
  +        for i := 0 to tmpToBeDeleted.Count - 1 do
  +        begin
  +          FFormulas.Delete(tmpToBeDeleted.Strings[i]);
           end;
  +
         finally
  -        FDataset.EnableControls;
  +        tmpToBeDeleted.Free;
         end;
       finally
         tmpNames.Free;
  
positive.code:   end;
  end;
  
  procedure TFormulaFieldsConfFrame.OnEditButtonClick(Sender: TObject);
  begin
    if FGrid.SelectedColumn.FieldName = 'FldFormula' then
    begin
      // todo
    end;
  end;
  
  procedure TFormulaFieldsConfFrame.OnEditingDone(Sender: TObject);
  begin
    if FGrid.SelectedColumn.FieldName = 'FldName' then
    begin
      FDataset.Edit;
      FDataset.FieldByName('FldName').AsString := StringReplace(Uppercase(Trim(FDataset.FieldByName('FldName').AsString)), ' ', '_', [rfReplaceAll]);
      FDataset.Post;
    end
    else
    if (FGrid.SelectedColumn.FieldName = 'FldSize') or (FGrid.SelectedColumn.FieldName = 'FldType') then
    begin
      if (FDataset.FieldByName('FldType').AsString = 'DOUBLE') or (FDataset.FieldByName('FldType').AsString = 'DATE') then
      begin
        FDataset.Edit;
        FDataset.FieldByName('FldSize').Clear;
        FDataset.Post;
      end;
    end;
  
  end;
  
  constructor TFormulaFieldsConfFrame.Create(TheOwner: TComponent);
  begin
    inherited Create(TheOwner);
    FDataSource := TDataSource.Create(Self);
    FDataset := TMemDataset.Create(Self);
  
    with FDataset.FieldDefs.AddFieldDef do
    begin
      Name := 'FldName';
      DataType:= ftString;
      Size := 100;
    end;
    with FDataset.FieldDefs.AddFieldDef do
    begin
      Name := 'FldType';
      DataType:= ftString;
      Size := 20;
    end;
    with FDataset.FieldDefs.AddFieldDef do
    begin
      Name := 'FldSize';
      DataType:= ftInteger;
    end;
    with FDataset.FieldDefs.AddFieldDef do
    begin
      Name := 'FldFormula';
      DataType:= ftString;
      Size := 500;
    end;
    FDataset.Active:= true;
  
    FDatasource.DataSet := FDataset;
  
    FGrid:= TmDBGrid.Create(Self);
    FGrid.Parent := Self;
    FGrid.Align:= alClient;
  
    FGrid.Options:= [dgEditing,dgTitles,dgIndicator,dgColumnResize,dgColumnMove,dgColLines,dgRowLines,dgTabs,dgAlwaysShowSelection,dgConfirmDelete,dgCancelOnExit];
    FGrid.OptionsExtra:=[dgeAutoColumns,dgeCheckboxColumn];
    FGrid.OnSelectEditor:= @OnSelectEditor;
    FGrid.OnEditButtonClick:= @OnEditButtonClick;
    FGrid.OnEditingDone:=@OnEditingDone;
    with FGrid.Columns.Add do
    begin
      // ReadOnly := True;
      Title.Caption := 'Name';
      Width := 250;
      FieldName := 'FldName';
    end;
    with FGrid.Columns.Add do
    begin
      Title.Caption := 'Type';
      FieldName := 'FldType';
      Width := 100;
      ButtonStyle:= cbsPickList;
    end;
  
negative.code:     function Check : boolean;
      procedure Init (aFormulas : TmFormulaFields);
      procedure UpdateFormulaFields;
    end;
  
  implementation
  
  uses
    Graphics,
    mUtility, mMathUtility;
  
  {$R *.lfm}
  
  