Bonjour,
je souhaiterais votre avis savoir si selon vous la procédure que j'ai créée pour lire un fichier JSON Vous paraît pas trop moche ? Par rapport entre autres au niveau de la création, libération des objets.
Merci par avance pour vos réponses.

Code JSON : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
    "DelphiVersions": [
        {
            "Name": "Delphi Rio",
            "RegistryPath": "SOFTWARE\\Embarcadero\\BDS\\20.0\\Library",
            "Path": [
                "Browsing Path",
                "Search Path",
                "Debug DCU Path"
            ]
        },
        {
            "Name": "Delphi Sydney",
            "RegistryPath": "SOFTWARE\\Embarcadero\\BDS\\21.0\\Library",
            "Path": [
                "Browsing Path",
                "Search Path",
                "Debug DCU Path"
            ]
        },
        {
            "Name": "Delphi Alexandria",
            "RegistryPath": "SOFTWARE\\Embarcadero\\BDS\\22.0\\Library",
            "Path": [
                "Browsing Path",
                "Search Path",
                "Debug DCU Path"
            ]
        },
        {
            "Name": "Delphi Athens",
            "RegistryPath": "SOFTWARE\\Embarcadero\\BDS\\23.0\\Library",
            "Path": [
                "Browsing Path",
                "Search Path",
                "Debug DCU Path"
            ]
        }
    ]
}

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
  TDelphiDetails = Class
    FName, FRegistryPath: String;
    FPath: TList<String>;
    Constructor Create(AName, ARegistryPath: String);
    Destructor Destroy; Override;
  End;
 
  TDelphiVersion = Class(TObjectList<TDelphiDetails>)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
Function TDelphiVersion.LoadFromFileDelphiVersion: Boolean;
Var
  JSONArray, JSONArrayPath: TJSONArray;
  JSONValue, JSONValueDelphiDetails, JSONValuePath: TJSONValue;
  Name, RegistryPath, Path: String;
  DelphiDetails: TDelphiDetails;
  sl: TStringList;
Begin
  sl        := TStringList.Create;
  JSONValue := Nil;
  Try
    sl.LoadFromFile(FileDelphiVersion);
    JSONValue := TJSONObject.ParseJSONValue(sl.Text);
 
    If Not JSONValue.TryGetValue<TJSONArray>('DelphiVersions', JSONArray) Then
      Exit(False);
 
    For JSONValueDelphiDetails In JSONArray Do
    Begin
      If Not JSONValueDelphiDetails.TryGetValue<String>('Name', Name) Then
        Exit(False);
 
      If Not JSONValueDelphiDetails.TryGetValue<String>('RegistryPath', RegistryPath) Then
        Exit(False);
 
      If Not JSONValueDelphiDetails.TryGetValue<TJSONArray>('Path', JSONArrayPath) Then
        Exit(False);
 
      DelphiDetails := TDelphiDetails.Create(Name, RegistryPath);
 
      For JSONValuePath In JSONArrayPath Do
      Begin
        If JSONValuePath.TryGetValue<String>(Path) Then
        Begin
          DelphiDetails.FPath.Add(Path);
        End;
      End;
 
      Add(DelphiDetails);
    End;
 
  Finally
    sl.Free;
    If Assigned(JSONValue) Then
      FreeAndNil(JSONValue);
  End;
 
  Result := True;
End;