Advertisement
Guest User

ini save/load function

a guest
Jan 17th, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.36 KB | None | 0 0
  1. 'Coded by VANS -=VANS-SOFT.RU=-'
  2.  
  3. //===================================================================
  4.  
  5. USES: iniFiles;
  6.  
  7. Глобальная переменная: ini:TIniFile;
  8.  
  9. //===================================================================
  10.  
  11. procedure TForm1.FormCreate(Sender: TObject);
  12. begin
  13.   ini:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'set.ini');
  14.   LoadFields(Form1);
  15. end;
  16.  
  17. procedure LoadFields(AParent: TWinControl);
  18. var i:integer;
  19. begin
  20.   for i:=0 to AParent.ControlCount-1 do begin
  21.     if AParent.Controls[i] is TsPanel then LoadFields(TsPanel(AParent.Controls[i]));
  22.     if AParent.Controls[i] is TsFilenameEdit then TsFilenameEdit(AParent.Controls[i]).Text:=ini.ReadString('settings', AParent.Controls[i].Name, '');
  23.     if AParent.Controls[i] is TsEdit then TsEdit(AParent.Controls[i]).Text:=ini.ReadString('settings', AParent.Controls[i].Name, '');
  24.     if AParent.Controls[i] is TsSpinEdit then TsSpinEdit(AParent.Controls[i]).Value:=ini.ReadInteger('settings', AParent.Controls[i].Name, 1000);
  25.     if AParent.Controls[i] is TsCheckBox then TsCheckBox(AParent.Controls[i]).Checked:=ini.ReadBool('settings', AParent.Controls[i].Name, false);
  26.     if AParent.Controls[i] is TsRadioButton then TsRadioButton(AParent.Controls[i]).Checked:=ini.ReadBool('settings', AParent.Controls[i].Name, false);
  27.   end;
  28. end;
  29.  
  30. procedure SaveFields(AParent: TWinControl);
  31. var i:integer;
  32. begin
  33.   for i:=0 to AParent.ControlCount-1 do begin
  34.     if AParent.Controls[i] is TsPanel then SaveFields(TsPanel(AParent.Controls[i]));
  35.     if AParent.Controls[i] is TsFilenameEdit then ini.WriteString('settings', AParent.Controls[i].Name, TsFilenameEdit(AParent.Controls[i]).Text);
  36.     if AParent.Controls[i] is TsEdit then ini.WriteString('settings', AParent.Controls[i].Name, TsEdit(AParent.Controls[i]).Text);
  37.     if AParent.Controls[i] is TsSpinEdit then ini.WriteInteger('settings', AParent.Controls[i].Name, TsSpinEdit(AParent.Controls[i]).Value);
  38.     if AParent.Controls[i] is TsCheckBox then ini.WriteBool('settings', AParent.Controls[i].Name, TsCheckBox(AParent.Controls[i]).Checked);
  39.     if AParent.Controls[i] is TsRadioButton then ini.WriteBool('settings', AParent.Controls[i].Name, TsRadioButton(AParent.Controls[i]).Checked);
  40.   end;
  41. end;
  42.  
  43. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  44. begin
  45.   SaveFields(Form1);
  46.   ini.Free;
  47. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement