|
1 | 1 | # Config |
2 | 2 | ### units de criação de banco de dados de valores de configuração no padrão `chave:valor` |
3 | 3 |
|
4 | | -### Exemplo antigo de uso para leitura: |
5 | | -<details> |
6 | | -<summary>código</summary> |
7 | | - |
8 | | -```Delphi |
9 | | -procedure TfConfig.CarregaConfig; |
10 | | -var |
11 | | - cfg: TSQLiteConfig; |
12 | | - JSONObj: TJSONObject; |
13 | | - I, J: Integer; |
14 | | -begin |
15 | | - cfg := TSQLiteConfig.Create; |
16 | | - JSONObj := cfg.LoadConfig; |
17 | | - try |
18 | | - if JSONObj.Count > 0 then |
19 | | - with Self do |
20 | | - for I := 0 to pred(ComponentCount) do |
21 | | - begin |
22 | | - if (Components[I] is TLabeledEdit) then |
23 | | - (Components[I] as TLabeledEdit).Text := |
24 | | - JSONObj.GetValue((Components[I] as TLabeledEdit).Name) |
25 | | - .ToString.Replace('"', ''); |
26 | | -
|
27 | | - if (Components[I] is TValueListEditor) then |
28 | | - for J := 1 to pred((Components[I] as TValueListEditor).RowCount) do |
29 | | - (Components[I] as TValueListEditor).Cells[1, J] := |
30 | | - JSONObj.GetValue((Components[I] as TValueListEditor).Keys[J]) |
31 | | - .ToString.Replace('"', ''); |
32 | | - end; |
33 | | - finally |
34 | | - JSONObj.Free; |
35 | | - cfg.Free; |
36 | | - end; |
37 | | -end; |
38 | | -``` |
39 | | -</details> |
40 | | - |
41 | | -### Exemplo novo de uso para leitura: |
42 | | -```Delphi |
43 | | -procedure TfConfig.CarregaConfig; |
44 | | -var |
45 | | - cfg: TSQLiteConfig; |
46 | | -begin |
47 | | - cfg := TSQLiteConfig.Create; |
48 | | - try |
49 | | - cfg.LoadForm(Self); |
50 | | - Finally |
51 | | - cfg.Free; |
52 | | - end; |
53 | | -end; |
54 | | -``` |
55 | | - |
56 | | -### Exemplo antigo de uso para gravação: |
57 | | -<details> <summary> código </summary> |
58 | | - |
59 | | -```Delphi |
60 | | -procedure TfConfig.SalvaConfig; |
61 | | -var |
62 | | - cfg: TSQLiteConfig; |
63 | | - JSONObj: TJSONObject; |
64 | | - I, J: Integer; |
65 | | -begin |
66 | | - cfg := TSQLiteConfig.Create; |
67 | | - JSONObj := TJSONObject.Create; |
68 | | - try |
69 | | - with Self do |
70 | | - for I := 0 to pred(ComponentCount) do |
71 | | - begin |
72 | | - if Components[I] is TLabeledEdit then |
73 | | - JSONObj.AddPair((Components[I] as TLabeledEdit).Name, |
74 | | - (Components[I] as TLabeledEdit).Text); |
75 | | -
|
76 | | - if (Components[I] is TValueListEditor) then |
77 | | - for J := 1 to pred((Components[I] as TValueListEditor).RowCount) do |
78 | | - JSONObj.AddPair((Components[I] as TValueListEditor).Keys[J], |
79 | | - (Components[I] as TValueListEditor).Cells[1, J]); |
80 | | - end; |
81 | | - cfg.UpdateConfig(JSONObj); |
82 | | - finally |
83 | | - JSONObj.Free; |
84 | | - cfg.Free; |
85 | | - end; |
86 | | -end; |
87 | | -``` |
88 | | -</details> |
89 | | - |
90 | | -### Exemplo novo de uso para gravação: |
91 | | -```Delphi |
92 | | -procedure TfConfig.SalvaConfig; |
93 | | -var |
94 | | - cfg: TSQLiteConfig; |
95 | | -begin |
96 | | - cfg := TSQLiteConfig.Create; |
97 | | - try |
98 | | - cfg.SaveForm(Self); |
99 | | - Finally |
100 | | - cfg.Free; |
101 | | - end; |
102 | | -end; |
103 | | -``` |
| 4 | +* Maiores informações: |
| 5 | +https://github.com/OpenSourceCommunityBrasil/PascalLibs/wiki/Config |
0 commit comments