Bläddra i källkod

QuickConfig Demo updated

Unknown 7 år sedan
förälder
incheckning
7428e3dff4

+ 40 - 18
samples/QuickConfig/Main.dfm

@@ -1,9 +1,10 @@
 object MainForm: TMainForm
 object MainForm: TMainForm
+  AlignWithMargins = True
   Left = 0
   Left = 0
   Top = 0
   Top = 0
   Caption = 'Quick Config Demo'
   Caption = 'Quick Config Demo'
-  ClientHeight = 274
-  ClientWidth = 337
+  ClientHeight = 347
+  ClientWidth = 523
   Color = clBtnFace
   Color = clBtnFace
   Font.Charset = DEFAULT_CHARSET
   Font.Charset = DEFAULT_CHARSET
   Font.Color = clWindowText
   Font.Color = clWindowText
@@ -11,32 +12,53 @@ object MainForm: TMainForm
   Font.Name = 'Tahoma'
   Font.Name = 'Tahoma'
   Font.Style = []
   Font.Style = []
   OldCreateOrder = False
   OldCreateOrder = False
+  OnClose = FormClose
   OnCreate = FormCreate
   OnCreate = FormCreate
   PixelsPerInch = 96
   PixelsPerInch = 96
   TextHeight = 13
   TextHeight = 13
   object meInfo: TMemo
   object meInfo: TMemo
-    Left = 16
-    Top = 16
-    Width = 305
-    Height = 209
+    Left = 8
+    Top = 8
+    Width = 507
+    Height = 273
+    ReadOnly = True
+    ScrollBars = ssBoth
     TabOrder = 0
     TabOrder = 0
   end
   end
-  object btnLoad: TButton
-    Left = 168
-    Top = 241
-    Width = 75
+  object btnLoadJson: TButton
+    Left = 208
+    Top = 287
+    Width = 145
     Height = 25
     Height = 25
-    Caption = 'Load'
+    Caption = 'Load From Json'
     TabOrder = 1
     TabOrder = 1
-    OnClick = btnLoadClick
+    OnClick = btnLoadJsonClick
   end
   end
-  object btnSave: TButton
-    Left = 249
-    Top = 241
-    Width = 75
+  object btnSaveJson: TButton
+    Left = 359
+    Top = 287
+    Width = 154
     Height = 25
     Height = 25
-    Caption = 'Save'
+    Caption = 'Save To Json'
     TabOrder = 2
     TabOrder = 2
-    OnClick = btnSaveClick
+    OnClick = btnSaveJsonClick
+  end
+  object btnLoadRegistry: TButton
+    Left = 208
+    Top = 318
+    Width = 145
+    Height = 25
+    Caption = 'Load From Registry'
+    TabOrder = 3
+    OnClick = btnLoadRegistryClick
+  end
+  object SaveRegistry: TButton
+    Left = 359
+    Top = 318
+    Width = 154
+    Height = 25
+    Caption = 'Save To Registry'
+    TabOrder = 4
+    OnClick = SaveRegistryClick
   end
   end
 end
 end

+ 166 - 21
samples/QuickConfig/Main.pas

@@ -3,62 +3,207 @@ unit Main;
 interface
 interface
 
 
 uses
 uses
-  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
-  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
-  Quick.Config, Vcl.StdCtrls;
+  Winapi.Windows,
+  Winapi.Messages,
+  System.SysUtils,
+  System.Variants,
+  System.Classes,
+  Vcl.Graphics,
+  Vcl.Controls,
+  Vcl.Forms,
+  Vcl.Dialogs,
+  Vcl.StdCtrls,
+  Quick.Config,
+  Quick.Config.Provider.Registry,
+  System.Generics.Collections,
+  Quick.Config.Provider.Json;
 
 
 type
 type
 
 
+  TMyPriority = (msLow, msMed, msHigh);
+
   TWinPos = record
   TWinPos = record
   public
   public
     PosX : Integer;
     PosX : Integer;
     PosY : Integer;
     PosY : Integer;
   end;
   end;
 
 
+  TProcessType = record
+    Id : Integer;
+    Priority : TMyPriority;
+    Redundant : Boolean;
+  end;
+
+  TWorker = class
+    Name : string;
+    Active : Boolean;
+  end;
+
   TMyConfig = class(TAppConfig)
   TMyConfig = class(TAppConfig)
+  private
+    fTitle : string;
+    fHidden : Boolean;
+    fSessionName: string;
   public
   public
+    Sizes : array of Integer;
     LastFilename : string;
     LastFilename : string;
     WindowPos : TWinPos;
     WindowPos : TWinPos;
+    History : array of TProcessType;
+    Complex : TProcessType;
+    ModifyDate : TDateTime;
+    WorkList : TObjectList<TWorker>;
+    destructor Destroy; override;
+    property Title : string read fTitle write fTitle;
+    property SessionName : string read fSessionName write fSessionName;
   end;
   end;
 
 
   TMainForm = class(TForm)
   TMainForm = class(TForm)
     meInfo: TMemo;
     meInfo: TMemo;
-    btnLoad: TButton;
-    btnSave: TButton;
+    btnLoadJson: TButton;
+    btnSaveJson: TButton;
+    btnLoadRegistry: TButton;
+    SaveRegistry: TButton;
     procedure FormCreate(Sender: TObject);
     procedure FormCreate(Sender: TObject);
-    procedure btnLoadClick(Sender: TObject);
-    procedure btnSaveClick(Sender: TObject);
-  private
-    { Private declarations }
-  public
-    { Public declarations }
+    procedure btnLoadJsonClick(Sender: TObject);
+    procedure btnSaveJsonClick(Sender: TObject);
+    procedure SaveRegistryClick(Sender: TObject);
+    procedure btnLoadRegistryClick(Sender: TObject);
+    procedure SetConfig(cConfig: TMyConfig);
+    function TestConfig(cConfig1, cConfig2: TMyConfig) : Boolean;
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
   end;
   end;
 
 
 var
 var
   MainForm: TMainForm;
   MainForm: TMainForm;
-  MyConfig : TMyConfig;
+  ConfigJson : TMyConfig;
+  ConfigReg : TMyConfig;
+  ConfigTest : TMyConfig;
+  AppConfigJson : TAppConfigJsonProvider<TMyConfig>;
+  AppConfigReg : TAppConfigRegistryProvider<TMyConfig>;
 
 
 implementation
 implementation
 
 
 {$R *.dfm}
 {$R *.dfm}
 
 
-procedure TMainForm.btnLoadClick(Sender: TObject);
+procedure TMainForm.btnLoadJsonClick(Sender: TObject);
+begin
+  meInfo.Lines.Add('Load ConfigJson');
+  AppConfigJson.Load(ConfigJson);
+  meInfo.Lines.Add(ConfigJson.ToJSON);
+  if TestConfig(ConfigTest,ConfigJson) then meInfo.Lines.Add('Test passed successfully!');
+end;
+
+procedure TMainForm.btnLoadRegistryClick(Sender: TObject);
+begin
+  meInfo.Lines.Add('Load ConfigReg');
+  AppConfigReg.Load(ConfigReg);
+  meInfo.Lines.Add(ConfigReg.ToJSON);
+  if TestConfig(ConfigTest,ConfigReg) then meInfo.Lines.Add('Test passed successfully!');
+end;
+
+procedure TMainForm.btnSaveJsonClick(Sender: TObject);
+begin
+  SetConfig(ConfigJson);
+  AppConfigJson.Save(ConfigJson);
+  meInfo.Lines.Add('Saved Config in Json at ' + DateTimeToStr(ConfigJson.LastSaved));
+end;
+
+procedure TMainForm.SaveRegistryClick(Sender: TObject);
+begin
+  SetConfig(ConfigReg);
+  AppConfigReg.Save(ConfigReg);
+  meInfo.Lines.Add('Saved Config in Registry at ' + DateTimeToStr(ConfigReg.LastSaved));
+end;
+
+procedure TMainForm.SetConfig(cConfig : TMyConfig);
+var
+  protype : TProcessType;
+  i : Integer;
+  worker : TWorker;
+begin
+  cConfig.LastFilename := 'library.txt';
+  cConfig.Sizes := [23,11,554,12,34,29,77,30,48,59,773,221,98,3,22,983,122,231,433,12,31,987];
+  cConfig.WindowPos.PosX := 640;
+  cConfig.WindowPos.PosX := 480;
+  cConfig.Complex.Priority := msHigh;
+  cConfig.Complex.Redundant := False;
+  cConfig.Title := 'a fresh title';
+  cConfig.SessionName := 'First Session';
+  if Assigned(cConfig.WorkList) then cconfig.WorkList.Free;
+  cConfig.WorkList := TObjectList<TWorker>.Create(True);
+  for I := 0 to 22 do
+  begin
+    worker := TWorker.Create;
+    worker.Name := 'Process ' + i.ToString;
+    worker.Active := Boolean(Random(1));
+    cConfig.WorkList.Add(worker);
+  end;
+  for i := 0 to 15 do
+  begin
+    protype.Id := i;
+    protype.Priority := msLow;
+    protype.Redundant := True;
+    cConfig.History := cConfig.History + [protype];
+  end;
+  cConfig.ModifyDate := Now();
+end;
+
+function  TMainForm.TestConfig(cConfig1, cConfig2 : TMyConfig) : Boolean;
+var
+  i : Integer;
 begin
 begin
-  MyConfig.Load(True);
-  meInfo.Lines.Text := MyConfig.AsJsonString;
+  try
+    Assert(cConfig1.LastFilename = cConfig2.LastFilename);
+    for i := Low(cConfig1.Sizes) to High(cConfig1.Sizes) do
+      Assert(cConfig1.Sizes[i] = cConfig2.Sizes[i]);
+    Assert(cConfig1.WindowPos.PosX = cConfig2.WindowPos.PosX);
+    Assert(cConfig1.WindowPos.PosX = cConfig2.WindowPos.PosX);
+    Assert(cConfig1.Complex.Priority = cConfig2.Complex.Priority);
+    Assert(cConfig1.Complex.Redundant  = cConfig2.Complex.Redundant);
+    Assert(cConfig1.Title = cConfig2.Title);
+    for i := 0 to cConfig1.WorkList.Count - 1 do
+    begin
+      Assert(cConfig1.WorkList[i].Name = cConfig2.WorkList[i].Name);
+      Assert(cConfig1.WorkList[i].Active = cConfig2.WorkList[i].Active);
+    end;
+    for i := 0 to High(cConfig1.History) do
+    begin
+      Assert(cConfig1.History[i].Priority = cConfig2.History[i].Priority);
+      Assert(cConfig1.History[i].Redundant = cConfig2.History[i].Redundant);
+    end;
+    Result := True;
+  except
+    ShowMessage('Configuration not has been saved previously or has a corruption problem');
+  end;
 end;
 end;
 
 
-procedure TMainForm.btnSaveClick(Sender: TObject);
+procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
 begin
 begin
-  MyConfig.LastFilename := 'notes.txt';
-  MyConfig.WindowPos.PosX := 200;
-  MyConfig.WindowPos.PosX := 100;
-  MyConfig.Save;
+  if Assigned(AppConfigJson) then AppConfigJson.Free;
+  if Assigned(AppConfigReg) then AppConfigReg.Free;
+  if Assigned(ConfigTest) then ConfigTest.Free;
+  if Assigned(ConfigReg) then ConfigReg.Free;
+  if Assigned(ConfigJson) then ConfigJson.Free;
 end;
 end;
 
 
 procedure TMainForm.FormCreate(Sender: TObject);
 procedure TMainForm.FormCreate(Sender: TObject);
 begin
 begin
-  MyConfig := TMyConfig.Create('prueba.json');
+  ConfigTest := TMyConfig.Create;
+  SetConfig(ConfigTest);
+  AppConfigJson := TAppConfigJsonProvider<TMyConfig>.Create(ConfigJson);
+  AppConfigJson.CreateIfNotExists := True;
+  AppConfigJson.Filename := 'Config.json';
+  AppConfigReg := TAppConfigRegistryProvider<TMyConfig>.Create(ConfigReg);
+  AppConfigReg.HRoot := HKEY_CURRENT_USER;
+  AppConfigReg.MainKey := '_AppConfig';
+end;
+
+{ TMyConfig }
+
+destructor TMyConfig.Destroy;
+begin
+  if Assigned(WorkList) then WorkList.Free;
+  inherited;
 end;
 end;
 
 
 end.
 end.

+ 1 - 0
samples/QuickConfig/QuickConfigDemo.dpr

@@ -7,6 +7,7 @@ uses
 {$R *.res}
 {$R *.res}
 
 
 begin
 begin
+  ReportMemoryLeaksOnShutdown := True;
   Application.Initialize;
   Application.Initialize;
   Application.MainFormOnTaskbar := True;
   Application.MainFormOnTaskbar := True;
   Application.CreateForm(TMainForm, MainForm);
   Application.CreateForm(TMainForm, MainForm);

+ 42 - 3
samples/QuickConfig/QuickConfigDemo.dproj

@@ -6,8 +6,8 @@
         <MainSource>QuickConfigDemo.dpr</MainSource>
         <MainSource>QuickConfigDemo.dpr</MainSource>
         <Base>True</Base>
         <Base>True</Base>
         <Config Condition="'$(Config)'==''">Debug</Config>
         <Config Condition="'$(Config)'==''">Debug</Config>
-        <Platform Condition="'$(Platform)'==''">Win32</Platform>
-        <TargetedPlatforms>1</TargetedPlatforms>
+        <Platform Condition="'$(Platform)'==''">Win64</Platform>
+        <TargetedPlatforms>3</TargetedPlatforms>
         <AppType>Application</AppType>
         <AppType>Application</AppType>
     </PropertyGroup>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
     <PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
@@ -34,6 +34,12 @@
         <Cfg_1>true</Cfg_1>
         <Cfg_1>true</Cfg_1>
         <Base>true</Base>
         <Base>true</Base>
     </PropertyGroup>
     </PropertyGroup>
+    <PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win64)'!=''">
+        <Cfg_1_Win64>true</Cfg_1_Win64>
+        <CfgParent>Cfg_1</CfgParent>
+        <Cfg_1>true</Cfg_1>
+        <Base>true</Base>
+    </PropertyGroup>
     <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
     <PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
         <Cfg_2>true</Cfg_2>
         <Cfg_2>true</Cfg_2>
         <CfgParent>Base</CfgParent>
         <CfgParent>Base</CfgParent>
@@ -45,6 +51,12 @@
         <Cfg_2>true</Cfg_2>
         <Cfg_2>true</Cfg_2>
         <Base>true</Base>
         <Base>true</Base>
     </PropertyGroup>
     </PropertyGroup>
+    <PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win64)'!=''">
+        <Cfg_2_Win64>true</Cfg_2_Win64>
+        <CfgParent>Cfg_2</CfgParent>
+        <Cfg_2>true</Cfg_2>
+        <Base>true</Base>
+    </PropertyGroup>
     <PropertyGroup Condition="'$(Base)'!=''">
     <PropertyGroup Condition="'$(Base)'!=''">
         <DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
         <DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
         <DCC_ExeOutput>.\$(Platform)\$(Config)</DCC_ExeOutput>
         <DCC_ExeOutput>.\$(Platform)\$(Config)</DCC_ExeOutput>
@@ -71,6 +83,12 @@
     </PropertyGroup>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Base_Win64)'!=''">
     <PropertyGroup Condition="'$(Base_Win64)'!=''">
         <DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;Intraweb;inetdb;EssentialsDR;vcwdXE11;FmxTeeUI;AbbreviaVCLD;fmx;fmxdae;tmsdXE11;vclib;tmsexdXE11;dbexpress;IndyCore;vclx;dsnap;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACMySQLDriver;FireDACCommonODBC;bindcompdbx;IndyIPCommon;vcl;IndyIPServer;IndySystem;advchartdxe11;dsnapcon;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDACPgDriver;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;Tee;xmlrtl;ibxbindings;fmxobj;vclwinx;rtl;DbxClientDriver;QuickVCL;CustomIPTransport;vcldsnap;DCEF_DX10;bindcomp;appanalytics;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;dsnapxml;dbrtl;inetdbxpress;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
         <DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;vcltouch;vcldb;bindcompfmx;Intraweb;inetdb;EssentialsDR;vcwdXE11;FmxTeeUI;AbbreviaVCLD;fmx;fmxdae;tmsdXE11;vclib;tmsexdXE11;dbexpress;IndyCore;vclx;dsnap;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACMySQLDriver;FireDACCommonODBC;bindcompdbx;IndyIPCommon;vcl;IndyIPServer;IndySystem;advchartdxe11;dsnapcon;FireDACMSAccDriver;fmxFireDAC;vclimg;TeeDB;FireDACPgDriver;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;Tee;xmlrtl;ibxbindings;fmxobj;vclwinx;rtl;DbxClientDriver;QuickVCL;CustomIPTransport;vcldsnap;DCEF_DX10;bindcomp;appanalytics;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;dsnapxml;dbrtl;inetdbxpress;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
+        <DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
+        <BT_BuildType>Debug</BT_BuildType>
+        <VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
+        <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
+        <VerInfo_Locale>1033</VerInfo_Locale>
+        <Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File>
     </PropertyGroup>
     </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_1)'!=''">
     <PropertyGroup Condition="'$(Cfg_1)'!=''">
         <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
         <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
@@ -85,6 +103,10 @@
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <AppEnableHighDPI>true</AppEnableHighDPI>
         <AppEnableHighDPI>true</AppEnableHighDPI>
     </PropertyGroup>
     </PropertyGroup>
+    <PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">
+        <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
+        <AppEnableHighDPI>true</AppEnableHighDPI>
+    </PropertyGroup>
     <PropertyGroup Condition="'$(Cfg_2)'!=''">
     <PropertyGroup Condition="'$(Cfg_2)'!=''">
         <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
         <DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
         <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
         <DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
@@ -95,6 +117,10 @@
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
         <AppEnableHighDPI>true</AppEnableHighDPI>
         <AppEnableHighDPI>true</AppEnableHighDPI>
     </PropertyGroup>
     </PropertyGroup>
+    <PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
+        <AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
+        <AppEnableHighDPI>true</AppEnableHighDPI>
+    </PropertyGroup>
     <ItemGroup>
     <ItemGroup>
         <DelphiCompile Include="$(MainSource)">
         <DelphiCompile Include="$(MainSource)">
             <MainSource>MainSource</MainSource>
             <MainSource>MainSource</MainSource>
@@ -125,12 +151,24 @@
                 </Source>
                 </Source>
             </Delphi.Personality>
             </Delphi.Personality>
             <Deployment Version="3">
             <Deployment Version="3">
+                <DeployFile LocalName="Win64\Debug\QuickConfigDemo.rsm" Configuration="Debug" Class="DebugSymbols">
+                    <Platform Name="Win64">
+                        <RemoteName>QuickConfigDemo.rsm</RemoteName>
+                        <Overwrite>true</Overwrite>
+                    </Platform>
+                </DeployFile>
                 <DeployFile LocalName="Win32\Debug\QuickConfigDemo.exe" Configuration="Debug" Class="ProjectOutput">
                 <DeployFile LocalName="Win32\Debug\QuickConfigDemo.exe" Configuration="Debug" Class="ProjectOutput">
                     <Platform Name="Win32">
                     <Platform Name="Win32">
                         <RemoteName>QuickConfigDemo.exe</RemoteName>
                         <RemoteName>QuickConfigDemo.exe</RemoteName>
                         <Overwrite>true</Overwrite>
                         <Overwrite>true</Overwrite>
                     </Platform>
                     </Platform>
                 </DeployFile>
                 </DeployFile>
+                <DeployFile LocalName="Win64\Debug\QuickConfigDemo.exe" Configuration="Debug" Class="ProjectOutput">
+                    <Platform Name="Win64">
+                        <RemoteName>QuickConfigDemo.exe</RemoteName>
+                        <Overwrite>true</Overwrite>
+                    </Platform>
+                </DeployFile>
                 <DeployClass Name="AdditionalDebugSymbols">
                 <DeployClass Name="AdditionalDebugSymbols">
                     <Platform Name="iOSSimulator">
                     <Platform Name="iOSSimulator">
                         <Operation>1</Operation>
                         <Operation>1</Operation>
@@ -549,8 +587,9 @@
             </Deployment>
             </Deployment>
             <Platforms>
             <Platforms>
                 <Platform value="Win32">True</Platform>
                 <Platform value="Win32">True</Platform>
-                <Platform value="Win64">False</Platform>
+                <Platform value="Win64">True</Platform>
             </Platforms>
             </Platforms>
+            <ModelSupport>False</ModelSupport>
         </BorlandProject>
         </BorlandProject>
         <ProjectFileVersion>12</ProjectFileVersion>
         <ProjectFileVersion>12</ProjectFileVersion>
     </ProjectExtensions>
     </ProjectExtensions>

BIN
samples/QuickConfig/QuickConfigDemo.res