Recent

Author Topic: How to save grid.font.size in inipropstorage (how use TStoredValue)  (Read 3699 times)

poiuyt555

  • Jr. Member
  • **
  • Posts: 91
Hi.
How to save grid.font.size in inipropstorage (how use TStoredValue)?
TStoredValue has properties (i set):
Name = Grid_Font_Size
Value = StringGrid1.Font.Size
KeyString = StringGrid1.Font.Size

And size is not saved and not load.
How do do it?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to save grid.font.size in inipropstorage (how use TStoredValue)
« Reply #1 on: April 29, 2013, 07:14:48 pm »
Try this. Start a new project, and drop a TStringGrid and a TiniPropStorage component on the form. Add OnCreate and OnClose handlers for the form, and complete them thus:

Code: [Select]
unit IniPSmain;

{$mode objfpc}{$H+}

interface

uses
  Forms, Grids, IniPropStorage;

type

  { TForm1 }

  TForm1 = class(TForm)
    ps: TIniPropStorage;
    sgrid: TStringGrid;
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

uses sysutils;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  ForceDirectories(GetAppConfigDir(False));
  ps.IniFileName:=GetAppConfigFile(False, False);
  ps.Active:=True;
  ps.IniSection:= 'sgrid.Font';
  sgrid.Font.Size:=17;
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  ps.StoredValue['sgrid.Font.Size']:= IntToStr(sgrid.Font.Size);
  CloseAction:=caFree;
end;

end.

Compile and run the project. Close the main form. Then look for a YourProjectName.cfg file in the appropriate directory for your OS.

poiuyt555

  • Jr. Member
  • **
  • Posts: 91
Thanks!

It works:
Code: [Select]
FormCreate:
IniPropStorage1.StoredValues.Add.DisplayName:= 'GridFontSize';

FormShow:
Stringgrid1.Font.Size := StrToIntDef(IniPropStorage1.StoredValue['GridFontSize'], Stringgrid1.Font.Size);

FormClose:
IniPropStorage1.StoredValue['GridFontSize'] := IntToStr(Stringgrid1.Font.Size);

 

TinyPortal © 2005-2018