Recent

Author Topic: (SOLVED) Save form status  (Read 2901 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
(SOLVED) Save form status
« on: February 14, 2017, 09:00:16 am »
Hello guys, I was wondering if there was a library or component to save the state in the form of components and designed above, column width type of grids, width of the form, etc. etc.
« Last Edit: February 17, 2017, 12:33:20 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Save form status
« Reply #1 on: February 14, 2017, 09:16:11 am »
For all of components it will be difficult but this method can give you idea:

You can change what do you want to save into inifile.

Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.LoadComponentValue(cmp: TComponent);
  2. const
  3.    section = 'COMP';
  4. begin
  5.   // Load component values from ini file
  6.   if (cmp is TEdit) then
  7.     with (cmp as TEdit) do
  8.       Text := iniF.ReadString(section,cmp.Name, Text );
  9.  
  10.   if (cmp is TCheckBox) then
  11.     with (cmp as TCheckBox) do
  12.       Checked := iniF.ReadBool(section,cmp.Name, Checked );
  13.  
  14.   if (cmp is TRadioButton) then
  15.     with (cmp as TRadioButton) do
  16.       Checked := iniF.ReadBool(section,cmp.Name, Checked );
  17.  
  18.   if (cmp is TListBox) then
  19.     with (cmp as TListBox) do
  20.       ItemIndex := iniF.ReadInteger(section,cmp.Name, ItemIndex );
  21.  
  22.   if (cmp is TComboBox) then
  23.     with (cmp as TComboBox) do
  24.       ItemIndex := iniF.ReadInteger(section,cmp.Name, ItemIndex );
  25.  
  26.   if (cmp is TFileNameEdit) then
  27.     with (cmp as TFileNameEdit) do
  28.       FileName := iniF.ReadString(section,cmp.Name, FileName );
  29.  
  30.   if (cmp is TFontDialog) then
  31.     with (cmp as TFontDialog) do
  32.     begin
  33.       Font.Color:=iniF.ReadInteger(section,cmp.Name+'.Font.Color', Font.Color);
  34.       iniF.WriteInteger(section,cmp.Name+'.Font.Size', Font.Size );
  35.     end;
  36.  
  37. end;
  38.  
  39. procedure TfrmMain.SaveComponentValue(cmp: TComponent);
  40. const
  41.    section = 'COMP';
  42. begin
  43.   // Save component values into ini file
  44.   if (cmp is TEdit) then
  45.     with (cmp as TEdit) do
  46.       iniF.WriteString(section,cmp.Name, Text );
  47.  
  48.   if (cmp is TCheckBox) then
  49.     with (cmp as TCheckBox) do
  50.       iniF.WriteBool(section,cmp.Name, Checked );
  51.  
  52.   if (cmp is TRadioButton) then
  53.     with (cmp as TRadioButton) do
  54.       iniF.WriteBool(section,cmp.Name, Checked );
  55.  
  56.   if (cmp is TListBox) then
  57.     with (cmp as TListBox) do
  58.       iniF.WriteInteger(section,cmp.Name, ItemIndex );
  59.  
  60.   if (cmp is TComboBox) then
  61.     with (cmp as TComboBox) do
  62.       iniF.WriteInteger(section,cmp.Name, ItemIndex );
  63.  
  64.   if (cmp is TFileNameEdit) then
  65.     with (cmp as TFileNameEdit) do
  66.       iniF.WriteString(section,cmp.Name, FileName );
  67.  
  68.   if (cmp is TFontDialog) then
  69.     with (cmp as TFontDialog) do
  70.     begin
  71.       iniF.WriteInteger(section,cmp.Name+'.Font.Color', Font.Color );
  72.       iniF.WriteInteger(section,cmp.Name+'.Font.Size', Font.Size );
  73.     end;
  74.  
  75. end;



Other method is TStream.WriteComponent();

balazsszekely

  • Guest
Re: Save form status
« Reply #2 on: February 14, 2017, 09:52:01 am »
Another, more generic solution: http://stackoverflow.com/a/3167505

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Save form status
« Reply #3 on: February 15, 2017, 08:37:39 am »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Save form status
« Reply #4 on: February 17, 2017, 12:33:09 pm »
Thank you :)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018