TMSFNCGrid SaveSettingsToFile/SaveSettingsToStream

Hello Support,

is it intended, that the procedure TTMSFNCCustomControl.SaveSettingsToFile(AFileName: string; AAppearanceOnly: Boolean = False); does not save the applied filters, sorting or grouping for the TTMSFNCGrid?

I would have guessed, that if woul work when the parameter AAppearanceOnly is set to True but that also doesn´t work :confused:

This would be a very much appreciated feature for us :slight_smile:

The SaveSettingsFile only saves the published properties. This is a method that comes automatically because of inheriting from TTMSFNCCustomControl. The filter is a public property.

1 Like

OK, that´s pretty unsatisfying...

Is there a way to save and restore the additional information in the exported json-file?
If not, is there another function that could be used to the layout of the TTMSFNCGrid?
I don´t need the data, just the layout.

unit Unit33;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.TMSFNCTypes, FMX.TMSFNCUtils, FMX.TMSFNCGraphics, FMX.TMSFNCGraphicsTypes,
  FMX.TMSFNCGridCell, FMX.TMSFNCGridOptions, FMX.TMSFNCCustomControl,
  FMX.TMSFNCCustomScrollControl, FMX.TMSFNCGridData, FMX.TMSFNCCustomGrid,
  FMX.TMSFNCGrid, FMX.Controls.Presentation, FMX.StdCtrls, FMX.TMSFNCPersistence, FMX.TMSFNCJSONWriter,
  FMX.TMSFNCJSONReader;

type
  TForm33 = class(TForm)
    TMSFNCGrid1: TTMSFNCGrid;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure DoWriteCustomProperty(AObject: TObject; APropertyName: string; APropertyKind: TTypeKind; AWriter: TTMSFNCJSONWriter; var ACanWrite: Boolean);
    procedure DoReadCustomProperty(AObject: TObject; APropertyName: string; APropertyKind: TTypeKind; AReader: TTMSFNCJSONReader; var ACanRead: Boolean);
  public
    { Public declarations }
  end;

var
  Form33: TForm33;

implementation

{$R *.fmx}

procedure TForm33.Button1Click(Sender: TObject);
begin
  TMSFNCGrid1.SaveSettingsToFile('test.json');
end;

procedure TForm33.Button2Click(Sender: TObject);
begin
  TMSFNCGrid1.BeginUpdate;
  TMSFNCGrid1.LoadSettingsFromFile('test.json');
  TMSFNCGrid1.EndUpdate;
end;

procedure TForm33.DoReadCustomProperty(AObject: TObject; APropertyName: string;
  APropertyKind: TTypeKind; AReader: TTMSFNCJSONReader; var ACanRead: Boolean);
var
  n: string;
  v: string;
begin
  if (AObject = TMSFNCGrid1) and (APropertyName = 'Adapter') then //NewProperty comes after Adapter
  begin
    ACanRead := False;
    AReader.SkipValue;
    n := AReader.ReadName; //NewProperty
    v := AReader.ReadString; //value
  end;
end;

procedure TForm33.DoWriteCustomProperty(AObject: TObject; APropertyName: string;
  APropertyKind: TTypeKind; AWriter: TTMSFNCJSONWriter; var ACanWrite: Boolean);
begin
  if (AObject = TMSFNCGrid1) and (APropertyName = 'AdaptToStyle') then //NewProperty comes before AdaptToStyle
  begin
    AWriter.WriteName('NewProperty');
    AWriter.WriteString('Value');
  end;
end;

procedure TForm33.FormCreate(Sender: TObject);
begin
  TTMSFNCPersistence.OnCustomWriteProperty := DoWriteCustomProperty;
  TTMSFNCPersistence.OnCustomReadProperty := DoReadCustomProperty;
  TMSFNCGrid1.LinearFill;
end;

end.

I tried using this but get the following error message when the DoReadCustomProperty is executed:
Error

Did you install the latest version of both TMS FNC Core & TMS FNC UI Pack?

I did upgrade to the newest version. But the Error is still thrown.

My Apologies, I noticed a small error. I updated the orginal code sample. The fix is located here:

procedure TForm33.DoReadCustomProperty(AObject: TObject; APropertyName: string;
  APropertyKind: TTypeKind; AReader: TTMSFNCJSONReader; var ACanRead: Boolean);
var
  n: string;
  v: string;
begin
  if (AObject = TMSFNCGrid1) and (APropertyName = 'Adapter') then //NewProperty comes after Adapter
  begin
    --> ACanRead := False;
    AReader.SkipValue;
    n := AReader.ReadName; //NewProperty
    v := AReader.ReadString; //value
  end;
end;