Changeset 561


Ignore:
Timestamp:
Sep 10, 2022, 6:26:39 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
  • Modified: Use Generics.Collections.
Location:
PersistentData
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • PersistentData/Backend/UPDClientINI.pas

    r361 r561  
    11unit UPDClientINI;
    2 
    3 {$mode delphi}
    42
    53interface
     
    2321    procedure Disconnect; override;
    2422  end;
     23
    2524
    2625implementation
     
    4948begin
    5049  Disconnect;
    51   inherited Destroy;
     50  inherited;
    5251end;
    5352
  • PersistentData/Backend/UPDClientMemory.pas

    r387 r561  
    11unit UPDClientMemory;
    2 
    3 {$mode Delphi}{$H+}
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, UPDClient, SpecializedList;
     6  Classes, SysUtils, UPDClient, Generics.Collections;
    97
    108type
     
    2119    function SearchObject(Id: Integer): TObjectProxy;
    2220  public
    23     Objects: TListObject;
     21    Objects: TObjectProxies;
    2422    procedure ObjectLoad(AObject: TObjectProxy); override;
    2523    procedure ObjectSave(AObject: TObjectProxy); override;
     
    4038resourcestring
    4139  SObjectNotFound = 'Object with id %s not found';
     40
    4241
    4342implementation
     
    9796    else begin
    9897      AObject.Id := GetNewObjectId;
    99       Obj := TObjectProxy(Objects.AddNew(TObjectProxy.Create));
     98      Obj := Objects.AddProxy;
    10099      Obj.Assign(AObject);
    101100    end;
     
    119118  NewObject: TObjectProxy;
    120119  Table: string;
     120  Item: TPair<string, string>;
    121121begin
    122122  AList.Objects.Clear;
     
    132132
    133133      if AList.ColummsFilterUse then begin
    134         for P := 0 to Properties.Count - 1 do
    135         if AList.ColumnsFilter.IndexOf(Properties.Keys[I]) <> -1 then
    136           NewObject.Properties.Add(Properties.Keys[I], Properties[I].Value);
     134        for Item in Properties do
     135        if AList.ColumnsFilter.IndexOf(Item.Key) <> -1 then
     136          NewObject.Properties.Add(Item.Key, Item.Value);
    137137      end else NewObject.Properties.Assign(Properties);
    138138    end;
     
    147147procedure TPDClientMemory.ListSave(AList: TListProxy);
    148148begin
    149 
    150149end;
    151150
    152151procedure TPDClientMemory.TypeDefine(AType: TPDType);
    153152begin
    154 
    155153end;
    156154
    157155procedure TPDClientMemory.TypeUndefine(AType: TPDType);
    158156begin
    159 
    160157end;
    161158
    162159function TPDClientMemory.TypeIsDefined(AType: TPDType): Boolean;
    163160begin
    164 
     161  Result := False;
    165162end;
    166163
    167164procedure TPDClientMemory.Install;
    168165begin
    169 
    170166end;
    171167
    172168procedure TPDClientMemory.Uninstall;
    173169begin
    174 
    175170end;
    176171
     
    178173begin
    179174  inherited;
    180   Objects := TListObject.Create;
     175  Objects := TObjectProxies.Create;
    181176  BackendName := 'Memory';
    182177end;
     
    184179destructor TPDClientMemory.Destroy;
    185180begin
    186   Objects.Free;
    187   inherited Destroy;
     181  FreeAndNil(Objects);
     182  inherited;
    188183end;
    189184
    190185procedure TPDClientMemory.Connect;
    191186begin
    192   inherited Connect;
     187  inherited;
    193188end;
    194189
    195190procedure TPDClientMemory.Disconnect;
    196191begin
    197   inherited Disconnect;
     192  inherited;
    198193end;
    199194
  • PersistentData/Backend/UPDClientMySQL.pas

    r362 r561  
    11unit UPDClientMySQL;
    22
    3 {$mode delphi}
    4 
    53interface
    64
    75uses
    8   Classes, SysUtils, USqlDatabase, UPDClient, SpecializedDictionary;
     6  Classes, SysUtils, USqlDatabase, UPDClient, UGenerics;
    97
    108type
     
    2220    function GetConnected: Boolean; override;
    2321    procedure Init; override;
     22    function GetConnectionString: string; override;
    2423  public
    2524    procedure ObjectLoad(AObject: TObjectProxy); override;
     
    4544  end;
    4645
     46
    4747implementation
    48 
    4948
    5049resourcestring
    5150  SMissingBaseType = 'Missing base typ for %s';
    5251  SUndefinedType = 'Undefined type in %0:s.%1:s';
    53 
    5452
    5553{ TPDClientMySQL }
     
    155153procedure TPDClientMySQL.ListSave(AList: TListProxy);
    156154begin
    157 
    158155end;
    159156
     
    245242end;
    246243
     244function TPDClientMySQL.GetConnectionString: string;
     245begin
     246  Result := 'Host:' + Host + ',Port:' + IntToStr(Port) + ',User:' + User +
     247    ',Password:' + Password + ',Schema:' + Schema;
     248end;
     249
    247250constructor TPDClientMySQL.Create(AOwner: TComponent);
    248251begin
     
    255258begin
    256259  FreeAndNil(FDatabase);
    257   inherited Destroy;
     260  inherited;
    258261end;
    259262
  • PersistentData/Backend/UPDClientRegistry.pas

    r361 r561  
    11unit UPDClientRegistry;
    2 
    3 {$mode delphi}
    42
    53interface
     
    1311
    1412  TPDClientRegistry = class(TPDClient)
     13  public
    1514    Reg: TRegistry;
    1615    //procedure GetItemList(Condition: TCondition; ItemList: TItemList); override;
     
    1918    destructor Destroy; override;
    2019  end;
     20
    2121
    2222implementation
     
    4646begin
    4747  Reg.Free;
    48   inherited Destroy;
     48  inherited;
    4949end;
    5050
  • PersistentData/Backend/UPDClientXMLRPC.pas

    r361 r561  
    11unit UPDClientXMLRPC;
    2 
    3 {$mode delphi}
    42
    53interface
     
    1614  end;
    1715
     16
    1817implementation
    19 
    2018
    2119{ TPDClientXMLRPC }
  • PersistentData/Demo/UFormMain.pas

    r361 r561  
    11unit UFormMain;
    2 
    3 {$mode delphi}{$H+}
    42
    53interface
     
    2220    procedure ComboBox1Change(Sender: TObject);
    2321    procedure FormShow(Sender: TObject);
    24   private
    25     { private declarations }
    2622  public
    2723    Client: TPDClient;
     
    3026var
    3127  FormMain: TFormMain;
     28
    3229
    3330implementation
  • PersistentData/PersistentData.lpk

    r362 r561  
    1 <?xml version="1.0"?>
     1<?xml version="1.0" encoding="UTF-8"?>
    22<CONFIG>
    3   <Package Version="4">
     3  <Package Version="5">
    44    <PathDelim Value="\"/>
    55    <Name Value="PersistentData"/>
     6    <Type Value="RunAndDesignTime"/>
    67    <Author Value="Chronos"/>
    78    <CompilerOptions>
     
    1011      <SearchPaths>
    1112        <OtherUnitFiles Value="Backend"/>
    12         <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     13        <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)-$(BuildMode)"/>
    1314      </SearchPaths>
    14       <CodeGeneration>
    15         <Checks>
    16           <IOChecks Value="True"/>
    17           <RangeChecks Value="True"/>
    18           <OverflowChecks Value="True"/>
    19           <StackChecks Value="True"/>
    20         </Checks>
    21       </CodeGeneration>
    22       <Other>
    23         <CompilerMessages>
    24           <MsgFileName Value=""/>
    25         </CompilerMessages>
    26         <CompilerPath Value="$(CompPath)"/>
    27       </Other>
     15      <Parsing>
     16        <SyntaxOptions>
     17          <SyntaxMode Value="Delphi"/>
     18          <CStyleOperator Value="False"/>
     19          <AllowLabel Value="False"/>
     20          <CPPInline Value="False"/>
     21        </SyntaxOptions>
     22      </Parsing>
     23      <Linking>
     24        <Debugging>
     25          <GenerateDebugInfo Value="False"/>
     26        </Debugging>
     27      </Linking>
    2828    </CompilerOptions>
    2929    <Description Value="Generic data persistence layer"/>
    3030    <License Value="GNU/GPL"/>
    31     <Version Minor="1"/>
     31    <Version Minor="2"/>
    3232    <Files Count="8">
    3333      <Item1>
     
    6565      </Item8>
    6666    </Files>
    67     <Type Value="RunAndDesignTime"/>
     67    <CompatibilityMode Value="True"/>
     68    <i18n>
     69      <EnableI18N Value="True"/>
     70    </i18n>
    6871    <RequiredPkgs Count="2">
    6972      <Item1>
  • PersistentData/UPDClient.pas

    r362 r561  
    11unit UPDClient;
    22
    3 {$mode delphi}
    4 
    53interface
    64
    75uses
    8   Classes, SysUtils, SpecializedList, SpecializedDictionary;
     6  Classes, SysUtils, Generics.Collections, UGenerics;
    97
    108const
     
    3331    destructor Destroy; override;
    3432    procedure Assign(Source: TObjectProxy);
     33  end;
     34
     35  { TObjectProxies }
     36
     37  TObjectProxies = class(TObjectList<TObjectProxy>)
     38    function AddProxy: TObjectProxy;
    3539  end;
    3640
     
    5963    ObjectName: string;
    6064    Path: string;
    61     Objects: TListObject; // TListObject<TObjectProxy>
     65    Objects: TObjectList<TObjectProxy>;
    6266    procedure Clear;
    6367    constructor Create;
     
    7478  end;
    7579
    76   { TPDTypePropertyList }
    77 
    78   TPDTypePropertyList = class(TListObject)
     80  { TPDTypeProperties }
     81
     82  TPDTypeProperties = class(TObjectList<TPDTypeProperty>)
    7983    Client: TPDClient;
    80     procedure AddSimple(Name: string; TypeName: string; Unique: Boolean = False;
    81       Index: Boolean = False);
     84    function AddSimple(Name: string; TypeName: string; Unique: Boolean = False;
     85      Index: Boolean = False): TPDTypeProperty;
    8286  end;
    8387
     
    9195    Name: string;
    9296    DbType: string;
    93     Properties: TPDTypePropertyList;
     97    Properties: TPDTypeProperties;
    9498    function IsDefined: Boolean;
    9599    procedure Define;
     
    100104  end;
    101105
    102   { TPDTypeList }
    103 
    104   TPDTypeList = class(TListObject)
     106  { TPDTypes }
     107
     108  TPDTypes = class(TObjectList<TPDType>)
    105109    Client: TPDClient;
    106110    function AddType(Name: string; DbType: string = ''): TPDType;
     
    121125    procedure SetConnectionString(AValue: string); virtual;
    122126  public
    123     Types: TPDTypeList;
     127    Types: TPDTypes;
    124128    Version: string;
    125129    BackendName: string;
     
    149153  TPDClientClass = class of TPDClient;
    150154
    151   resourcestring
    152     SClientNotSet = 'Client not set';
    153     SNotSupported = 'Not supported';
    154     SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.';
    155     SCantLoadObjectWithoutId = 'Can''t load object without id';
     155resourcestring
     156  SClientNotSet = 'Client not set';
     157  SNotSupported = 'Not supported';
     158  SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.';
     159  SCantLoadObjectWithoutId = 'Can''t load object without id';
    156160
    157161
    158162implementation
    159163
    160 { TPDTypePropertyList }
    161 
    162 procedure TPDTypePropertyList.AddSimple(Name: string; TypeName: string;
    163   Unique: Boolean; Index: Boolean);
    164 var
    165   NewProperty: TPDTypeProperty;
    166 begin
    167   NewProperty := TPDTypeProperty(AddNew(TPDTypeProperty.Create));
    168   NewProperty.Name := Name;
    169   NewProperty.DbType := Client.Types.SearchByName(TypeName);
    170   NewProperty.Unique := Unique;
    171   NewProperty.Index := Index;
    172 end;
    173 
    174 
    175 { TPDTypeList }
    176 
    177 function TPDTypeList.AddType(Name: string; DbType: string = ''): TPDType;
    178 begin
    179   Result := TPDType(AddNew(TPDType.Create));
     164{ TObjectProxies }
     165
     166function TObjectProxies.AddProxy: TObjectProxy;
     167begin
     168  Result := TObjectProxy.Create;
     169  Add(Result);
     170end;
     171
     172{ TPDTypeProperties }
     173
     174function TPDTypeProperties.AddSimple(Name: string; TypeName: string;
     175  Unique: Boolean = False; Index: Boolean = False): TPDTypeProperty;
     176begin
     177  Result := TPDTypeProperty.Create;
     178  Result.Name := Name;
     179  Result.DbType := Client.Types.SearchByName(TypeName);
     180  Result.Unique := Unique;
     181  Result.Index := Index;
     182  Add(Result);
     183end;
     184
     185{ TPDTypes }
     186
     187function TPDTypes.AddType(Name: string; DbType: string = ''): TPDType;
     188begin
     189  Result := TPDType.Create;
    180190  Result.Client := Client;
    181191  Result.Name := Name;
    182192  Result.DbType := DbType;
    183 end;
    184 
    185 function TPDTypeList.SearchByName(Name: string): TPDType;
     193  Add(Result);
     194end;
     195
     196function TPDTypes.SearchByName(Name: string): TPDType;
    186197var
    187198  I: Integer;
     
    220231constructor TPDType.Create;
    221232begin
    222   Properties := TPDTypePropertyList.Create;
     233  Properties := TPDTypeProperties.Create;
    223234end;
    224235
    225236destructor TPDType.Destroy;
    226237begin
    227   Properties.Free;
    228   inherited Destroy;
     238  FreeAndNil(Properties);
     239  inherited;
    229240end;
    230241
     
    256267destructor TObjectProxy.Destroy;
    257268begin
    258   Properties.Free;
    259   inherited Destroy;
     269  FreeAndNil(Properties);
     270  inherited;
    260271end;
    261272
     
    282293begin
    283294  ColumnsFilter := TListString.Create;
    284   Objects := TListObject.Create;
     295  Objects := TObjectList<TObjectProxy>.Create;
    285296end;
    286297
    287298destructor TListProxy.Destroy;
    288299begin
    289   Objects.Free;
    290   ColumnsFilter.Free;
    291   inherited Destroy;
     300  FreeAndNil(Objects);
     301  FreeAndNil(ColumnsFilter);
     302  inherited;
    292303end;
    293304
     
    313324procedure TPDClient.SetConnectionString(AValue: string);
    314325begin
    315 
    316326end;
    317327
     
    347357    NewObject.Load;
    348358
    349     DbVersion := NewObject.Properties.Values['Version'];
     359    DbVersion := NewObject.Properties.Items['Version'];
    350360    if Version <> DbVersion then
    351361      raise Exception.Create(Format(SVersionMismatch, [Version, DbVersion]));
     
    397407    Tables.Count := NewProxy.Objects.Count;
    398408    for I := 0 to NewProxy.Objects.Count - 1 do
    399       Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Values['TABLE_NAME'];
     409      Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Items['TABLE_NAME'];
    400410
    401411    for I := 0 to Types.Count - 1 do
     
    415425begin
    416426  inherited;
    417   Types := TPDTypeList.Create;
     427  Types := TPDTypes.Create;
    418428  Types.Client := Self;
    419429  InitSystemTypes;
     
    422432destructor TPDClient.Destroy;
    423433begin
    424   Types.Free;
    425   inherited Destroy;
     434  FreeAndNil(Types);
     435  inherited;
    426436end;
    427437
     
    436446procedure TPDClient.Install;
    437447begin
    438 
    439448end;
    440449
     
    446455procedure TPDClient.Update;
    447456begin
    448 
    449457end;
    450458
  • PersistentData/UPDServer.pas

    r340 r561  
    11unit UPDServer;
    2 
    3 {$mode delphi}
    42
    53interface
     
    108type
    119  TPDServer = class
     10  end;
    1211
    13   end;
    1412
    1513implementation
  • PersistentData/UPersistentData.pas

    r361 r561  
    11unit UPersistentData;
    2 
    3 {$mode delphi}{$H+}
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, UPDClient, SpecializedList;
     6  Classes, SysUtils, UPDClient, Generics.Collections;
    97
    108type
     
    1412  end;
    1513
     14  TPDManagerItems = class(TObjectList<TPDManagerItem>)
     15  end;
     16
    1617  { TPDManager }
    1718
    1819  TPDManager = class(TComponent)
    19     Items: TListObject;
     20  public
     21    Items: TPDManagerItems;
    2022    procedure Register(ClientClass: TPDClientClass);
    2123    procedure LoadToStrings(Strings: TStrings);
     
    7779begin
    7880  inherited;
    79   Items := TListObject.Create;
     81  Items := TPDManagerItems.Create;
    8082end;
    8183
     
    8385begin
    8486  FreeAndNil(Items);
    85   inherited Destroy;
     87  inherited;
    8688end;
    8789
Note: See TracChangeset for help on using the changeset viewer.