Ignore:
Timestamp:
Jan 1, 2018, 8:57:03 PM (7 years ago)
Author:
chronos
Message:
  • Added: Remember players configuration in XML config file between application runs.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.pas

    r34 r36  
    66
    77uses
    8   Registry, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
    9   ComCtrls, Menus, ActnList, UCore, UPlatform, Math, DateUtils, GraphType,
    10   UPersistentForm, UApplicationInfo, UCoolTranslator, LCLType, URegistry;
     8  Registry, XMLConf, Classes, SysUtils, FileUtil, Forms, Controls, Graphics,
     9  Dialogs, ExtCtrls, ComCtrls, Menus, ActnList, UCore, UPlatform, Math,
     10  DateUtils, GraphType, UPersistentForm, UApplicationInfo, UCoolTranslator,
     11  LCLType, URegistry;
    1112
    1213type
     
    3738    TimerDraw: TTimer;
    3839    TimerEngineTick: TTimer;
     40    XMLConfig1: TXMLConfig;
    3941    procedure AExitExecute(Sender: TObject);
    4042    procedure AFullScreenExecute(Sender: TObject);
     
    6062    DrawDuration: TDateTime;
    6163    Drawing: Boolean;
     64    procedure LoadConfig;
     65    procedure SaveConfig;
    6266  public
    6367    PersistentForm: TPersistentForm;
     
    110114end;
    111115
     116procedure TMainForm.LoadConfig;
     117begin
     118  if not FileExists(XMLConfig1.Filename) then Exit;
     119  if Assigned(Engine) then Engine.LoadConfig(XMLConfig1, '');
     120end;
     121
     122procedure TMainForm.SaveConfig;
     123begin
     124  if Assigned(Engine) then Engine.SaveConfig(XMLConfig1, '');
     125  XMLConfig1.Flush;
     126end;
     127
    112128procedure TMainForm.EraseBackground(DC: HDC);
    113129begin
     
    117133procedure TMainForm.FormCreate(Sender: TObject);
    118134begin
     135  XMLConfig1.Filename := GetAppConfigDir(False) + 'Config.xml';
     136
    119137  PersistentForm := TPersistentForm.Create(nil);
    120138  PersistentForm.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
     
    126144  Engine := TEngine.Create;
    127145  Engine.Bitmap := Image1.Picture.Bitmap;
     146  LoadConfig;
    128147  Engine.NewGame;
    129148  Engine.Active := True;
     
    193212begin
    194213  PersistentForm.Save(Self);
     214  SaveConfig;
    195215end;
    196216
Note: See TracChangeset for help on using the changeset viewer.