├── .gitignore
├── README.md
├── Samples
└── Demo01
│ ├── C4DValidateComponentsDemo01.dpr
│ ├── C4DValidateComponentsDemo01.dproj
│ ├── C4DValidateComponentsDemo01.res
│ └── Src
│ ├── Utils
│ └── C4D.ValidateComponents.Demo01.Utils.pas
│ └── View
│ ├── C4D.ValidateComponents.Demo01.View.Main.dfm
│ └── C4D.ValidateComponents.Demo01.View.Main.pas
├── Src
├── C4D.Validate.Components.Components.pas
├── C4D.Validate.Components.Config.pas
├── C4D.Validate.Components.Consts.pas
├── C4D.Validate.Components.Errors.pas
├── C4D.Validate.Components.FieldDisplay.pas
├── C4D.Validate.Components.Helpers.pas
├── C4D.Validate.Components.Language.pas
├── C4D.Validate.Components.Length.pas
├── C4D.Validate.Components.ListPair.pas
├── C4D.Validate.Components.MinMaxDate.pas
├── C4D.Validate.Components.MinMaxValue.pas
├── C4D.Validate.Components.NotEmpty.pas
├── C4D.Validate.Components.SetFocus.pas
├── C4D.Validate.Components.Types.pas
└── C4D.Validate.Components.pas
├── boss-lock.json
└── boss.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Uncomment these types if you want even more clean repository. But be careful.
2 | # It can make harm to an existing project source. Read explanations below.
3 | #
4 | # Resource files are binaries containing manifest, project icon and version info.
5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
6 | #*.res
7 | #
8 | # Type library file (binary). In old Delphi versions it should be stored.
9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
10 | #*.tlb
11 | #
12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
13 | # Uncomment this if you are not using diagrams or use newer Delphi version.
14 | #*.ddp
15 | #
16 | # Visual LiveBindings file. Added in Delphi XE2.
17 | # Uncomment this if you are not using LiveBindings Designer.
18 | #*.vlb
19 | #
20 | # Deployment Manager configuration file for your project. Added in Delphi XE2.
21 | # Uncomment this if it is not mobile development and you do not use remote debug feature.
22 | #*.deployproj
23 | #
24 | # C++ object files produced when C/C++ Output file generation is configured.
25 | # Uncomment this if you are not using external objects (zlib library for example).
26 | #*.obj
27 | #
28 |
29 | # Delphi compiler-generated binaries (safe to delete)
30 | *.exe
31 | *.dll
32 | *.bpl
33 | *.bpi
34 | *.dcp
35 | *.so
36 | *.apk
37 | *.drc
38 | *.map
39 | *.dres
40 | *.rsm
41 | *.tds
42 | *.dcu
43 | *.lib
44 | *.a
45 | *.o
46 | *.ocx
47 |
48 | # Delphi autogenerated files (duplicated info)
49 | *.cfg
50 | *.hpp
51 | *Resource.rc
52 |
53 | # Delphi local files (user-specific info)
54 | *.local
55 | *.identcache
56 | *.projdata
57 | *.tvsconfig
58 | *.dsk
59 |
60 | # Delphi history and backups
61 | __history/
62 | __recovery/
63 | *.~*
64 |
65 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi)
66 | *.stat
67 |
68 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss
69 | modules/
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # C4D Validate Components
2 |
3 |
4 |
5 |
6 |
7 | Utility for automatic validation of Delphi forms. Excellent to be used for both new projects and legacy products. Facilitating form field validations and reducing code complexity. It can be used for both DBWare and non-DBWare components.
8 |
9 |
10 |
11 | ## 📞 Contacts
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | ## ⚙️ Installation
34 |
35 | * Installation using the [**Boss**](https://github.com/HashLoad/boss):
36 |
37 | ```
38 | boss install github.com/Code4Delphi/C4D-Validate-Components
39 | ```
40 |
41 | * **Manual installation**: Open your Delphi and add the following folder to your project, under *Project > Options > Resource Compiler > Directories and Conditionals > Include file search path*
42 |
43 | ```
44 | ..\C4D-Validate-Components\Src
45 | ```
46 |
47 |
48 |
49 | ## 🚀 Quickstart
50 | * Add uses to your system:
51 | ```
52 | uses
53 | C4D.Validate.Components;
54 | ```
55 |
56 | * Insert the Custom Attributes on the component declaration you want to validate:
57 | ```
58 | [FieldDisplay('Name')]
59 | [NotEmpty]
60 | [Length(5, 15)]
61 | edtName: TEdit;
62 | ```
63 |
64 | * Make the call for form validation:
65 | ```
66 | TC4DValidateComponents.Validate(TClasseDoForm, Self);
67 | ```
68 |
69 | ## Custom Attributes available:
70 |
71 | * Name to be displayed if there are errors:
72 | ```
73 | [FieldDisplay('Name to be displayed')]
74 | ```
75 |
76 | * Validates so that the field is not empty:
77 | ```
78 | [NotEmpty]
79 | ```
80 |
81 | * Enter a minimum and/or maximum number of characters for the field:
82 | ```
83 | [Length(5, 15)]
84 | ```
85 |
86 | * Enter the minimum and/or maximum value that must be entered in the field:
87 | ```
88 | [MinMaxValue(5, 10)]
89 | ```
90 |
91 | * Enter the minimum and/or maximum date that must be entered in the field
92 | ```
93 | [MinMaxDate('01/12/2023', '10/12/2023')]
94 | ```
95 |
96 | ## ⌨️ Demo
97 | * Next to the project sources, you will find a test project, in the folder:
98 | ```
99 | C4D-Validate-Components\Samples\Demo01
100 | ```
101 |
102 |
103 |
104 |
105 | > [!TIP]
106 | > Starting with Delphi version 10.3, if you use a custom attribute that is not known to the compiler (because you typed it incorrectly or a unit is missing in the uses statement), you will receive a Warning:
107 | > ```
108 | > Warning: W1074 Unknown custom attribute
109 | > ```
110 | > It is recommended to transform this Warning into an error, so that correction is mandatory, to do so enter:
111 | > ```
112 | > {$WARN UNKNOWN_CUSTOM_ATTRIBUTE ERROR}
113 | > ```
114 |
115 |
116 | # 💬 Contributions / Ideas / Bug Fixes
117 | To submit a pull request, follow these steps:
118 |
119 | 1. Fork the project
120 | 2. Create a new branch (`git checkout -b minha-nova-funcionalidade`)
121 | 3. Make your changes
122 | 4. Make the commit (`git commit -am 'Functionality or adjustment message'`)
123 | 5. Push the branch (`git push origin Message about functionality or adjustment`)
124 | 6. Open a pull request
125 |
--------------------------------------------------------------------------------
/Samples/Demo01/C4DValidateComponentsDemo01.dpr:
--------------------------------------------------------------------------------
1 | program C4DValidateComponentsDemo01;
2 |
3 | uses
4 | Vcl.Forms,
5 | C4D.ValidateComponents.Demo01.View.Main in 'Src\View\C4D.ValidateComponents.Demo01.View.Main.pas' {C4DValidateComponentsDemo01ViewMain},
6 | C4D.Validate.Components.Components in '..\..\Src\C4D.Validate.Components.Components.pas',
7 | C4D.Validate.Components.NotEmpty in '..\..\Src\C4D.Validate.Components.NotEmpty.pas',
8 | C4D.Validate.Components.Length in '..\..\Src\C4D.Validate.Components.Length.pas',
9 | C4D.Validate.Components.MinMaxValue in '..\..\Src\C4D.Validate.Components.MinMaxValue.pas',
10 | C4D.Validate.Components in '..\..\Src\C4D.Validate.Components.pas',
11 | C4D.Validate.Components.FieldDisplay in '..\..\Src\C4D.Validate.Components.FieldDisplay.pas',
12 | C4D.Validate.Components.Helpers in '..\..\Src\C4D.Validate.Components.Helpers.pas',
13 | C4D.ValidateComponents.Demo01.Utils in 'Src\Utils\C4D.ValidateComponents.Demo01.Utils.pas',
14 | C4D.Validate.Components.MinMaxDate in '..\..\Src\C4D.Validate.Components.MinMaxDate.pas',
15 | C4D.Validate.Components.Consts in '..\..\Src\C4D.Validate.Components.Consts.pas',
16 | C4D.Validate.Components.Language in '..\..\Src\C4D.Validate.Components.Language.pas',
17 | C4D.Validate.Components.Config in '..\..\Src\C4D.Validate.Components.Config.pas',
18 | C4D.Validate.Components.Types in '..\..\Src\C4D.Validate.Components.Types.pas',
19 | C4D.Validate.Components.Errors in '..\..\Src\C4D.Validate.Components.Errors.pas',
20 | C4D.Validate.Components.ListPair in '..\..\Src\C4D.Validate.Components.ListPair.pas',
21 | C4D.Validate.Components.SetFocus in '..\..\Src\C4D.Validate.Components.SetFocus.pas';
22 |
23 | {$R *.res}
24 |
25 |
26 | begin
27 | Application.Initialize;
28 | Application.MainFormOnTaskbar := True;
29 | Application.CreateForm(TC4DValidateComponentsDemo01ViewMain, C4DValidateComponentsDemo01ViewMain);
30 | Application.Run;
31 |
32 | end.
33 |
--------------------------------------------------------------------------------
/Samples/Demo01/C4DValidateComponentsDemo01.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {94F04652-63C9-40C5-A554-2267D8E1A9D2}
4 | 18.8
5 | VCL
6 | C4DValidateComponentsDemo01.dpr
7 | True
8 | Debug
9 | Win32
10 | 1
11 | Application
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | true
28 | Base
29 | true
30 |
31 |
32 | true
33 | Cfg_1
34 | true
35 | true
36 |
37 |
38 | true
39 | Base
40 | true
41 |
42 |
43 | true
44 | Cfg_2
45 | true
46 | true
47 |
48 |
49 | .\$(Platform)\$(Config)
50 | .\$(Platform)\$(Config)
51 | false
52 | false
53 | false
54 | false
55 | false
56 | System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)
57 | $(BDS)\bin\delphi_PROJECTICON.ico
58 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png
59 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png
60 | C4DValidateComponentsDemo01
61 |
62 |
63 | DBXSqliteDriver;DBXDb2Driver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;ACBr_BoletoFPDF;ACBr_BPeDabpeESCPOS;ACBr_BPe;FireDACMSSQLDriver;vcltouch;ACBr_NFe;ACBr_NFeDanfeFR;vcldb;svn;ACBr_NFeDanfeESCPOS;ACBr_PAFNFCe;ACBr_OFX;vclib;frxTee26;ACBr_SATExtratoFR;FireDACDBXDriver;ACBr_NFSeDanfseFR;vclx;ACBr_SATExtratoRL;ACBr_GTIN;RESTBackendComponents;ACBr_Reinf;VCLRESTComponents;fsTee26;vclie;bindengine;CloudService;ACBr_PAF;FireDACMySQLDriver;fsIBX26;ACBr_SATECFVirtual;frx26;C4DMaskEdit;DataSnapClient;ACBr_OpenDelivery;bindcompdbx;ACBr_CTeDacteRL;ACBr_TCP;DBXSybaseASEDriver;IndyIPServer;ACBr_CTe;IndySystem;frxDBX26;fsADO26;ACBr_PagFor;dsnapcon;VirtualTreesR;ACBre_Social;FireDACMSAccDriver;FireDACInfxDriver;fmxFireDAC;vclimg;ACBr_SPEDImportar;bsfd103Rio;mydacvcl260;ACBr_SPED;ACBr_MDFe;emshosting;ACBr_BoletoRL;ACBr_LFD;DBXOdbcDriver;FireDACTDataDriver;FMXTee;crcontrols260;soaprtl;DbxCommonDriver;ACBr_CIOT;C4DWizard;ACBr_NFSeDanfseRL;xmlrtl;DataSnapNativeClient;soapmidas;fmxobj;rtl;emsserverresource;DbxClientDriver;DBXSybaseASADriver;pkItemMenuHelpDelphi;ACBr_Convenio115;appanalytics;ACBr_DebitoAutomatico;IndyIPClient;bindcompvcl;TeeUI;ACBr_NFSeXDANFSeFR;VclSmp;FireDACODBCDriver;mydacfmx260;DataSnapIndy10ServerTransport;ACBr_Boleto;DataSnapProviderClient;ACBr_SEF2;FireDACMongoDBDriver;ACBr_MDFeDamdfeFR;ACBr_NFSe;DataSnapServerMidas;RESTComponents;ZComponent;DBXInterBaseDriver;ACBr_NF3e;ZCore;ACBr_TEFD;emsclientfiredac;dacfmx260;DataSnapFireDAC;svnui;FMXAdvancedControls;ACBr_SATWS;DBXMSSQLDriver;ACBr_MDFeDamdfeRL;DatasnapConnectorsFreePascal;PngComponentsD;ACBr_EDI;ACBr_ONE;DBXOracleDriver;inetdb;ACBr_Diversos;ACBr_GNREGuiaFR;FmxTeeUI;emsedge;ACBr_LCDPR;FireDACIBDriver;fmx;fmxdae;DSPack_DXE2;ACBr_CTeDacteFR;MSNPopUp_D104;ZipMasterR;dacvcl260;ACBr_Ponto;fs26;dbexpress;IndyCore;frxIntIO26;ZParseSql;dsnap;DataSnapCommon;emsclient;FireDACCommon;frxcs26;ACBr_NFSeX;DataSnapConnectors;ACBR_DeSTDA;soapserver;ACBr_SAT;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;ACBr_Sintegra;FireDACCommonODBC;FireDACCommonDriver;ACBr_ADRCST;ACBr_GNRE;frxIntIOIndy26;inet;IndyIPCommon;vcl;ACBr_NFeDanfeRL;ACBr_SATExtratoESCPOS;frxDB26;FireDACDb2Driver;ACBr_Integrador;fsDB26;ZDbc;TeeDB;FireDAC;mydac260;ACBr_Comum;frxe26;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;ACBr_GNREGuiaRL;C4DDateEdit;frxIBX26;VDOPrint;ibxpress;Tee;DataSnapServer;ibxbindings;BossExperts;dac260;FireDACDSDriver;vclwinx;mysqlmon260;ACBr_OpenSSL;frxADO26;CustomIPTransport;vcldsnap;ACBr_PIXCD;bindcomp;ZPlain;RtmRxCtl270;DBXInformixDriver;ACBr_Serial;frce;ACBr_NFSeXDanfseRL;ACBr_BlocoX;dbxcds;ACBr_NFCeECFVirtual;adortl;ACBr_BoletoFR;ACBr_ANe;dsnapxml;dbrtl;IndyProtocols;inetdbxpress;ACBr_NF3eDANF3eESCPOS;ACBr_MTER;fmxase;$(DCC_UsePackage)
64 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
65 | Debug
66 | true
67 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=
68 | 1033
69 | $(BDS)\bin\default_app.manifest
70 |
71 |
72 | DBXSqliteDriver;DBXDb2Driver;vclactnband;vclFireDAC;tethering;FireDACADSDriver;FireDACMSSQLDriver;vcltouch;vcldb;vclib;FireDACDBXDriver;vclx;RESTBackendComponents;VCLRESTComponents;vclie;bindengine;CloudService;FireDACMySQLDriver;DataSnapClient;bindcompdbx;DBXSybaseASEDriver;IndyIPServer;IndySystem;dsnapcon;VirtualTreesR;FireDACMSAccDriver;FireDACInfxDriver;fmxFireDAC;vclimg;emshosting;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;xmlrtl;DataSnapNativeClient;soapmidas;fmxobj;rtl;emsserverresource;DbxClientDriver;DBXSybaseASADriver;appanalytics;IndyIPClient;bindcompvcl;TeeUI;VclSmp;FireDACODBCDriver;DataSnapIndy10ServerTransport;DataSnapProviderClient;FireDACMongoDBDriver;DataSnapServerMidas;RESTComponents;ZComponent;DBXInterBaseDriver;ZCore;emsclientfiredac;DataSnapFireDAC;DBXMSSQLDriver;DatasnapConnectorsFreePascal;PngComponentsD;DBXOracleDriver;inetdb;FmxTeeUI;emsedge;FireDACIBDriver;fmx;fmxdae;DSPack_DXE2;dbexpress;IndyCore;ZParseSql;dsnap;DataSnapCommon;emsclient;FireDACCommon;DataSnapConnectors;soapserver;FireDACOracleDriver;DBXMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;FireDACCommonDriver;inet;IndyIPCommon;vcl;FireDACDb2Driver;ZDbc;TeeDB;FireDAC;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;ibxpress;Tee;DataSnapServer;ibxbindings;FireDACDSDriver;vclwinx;CustomIPTransport;vcldsnap;bindcomp;ZPlain;DBXInformixDriver;dbxcds;adortl;dsnapxml;dbrtl;IndyProtocols;inetdbxpress;fmxase;$(DCC_UsePackage)
73 |
74 |
75 | DEBUG;$(DCC_Define)
76 | true
77 | false
78 | true
79 | true
80 | true
81 |
82 |
83 | false
84 | true
85 | PerMonitorV2
86 |
87 |
88 | false
89 | RELEASE;$(DCC_Define)
90 | 0
91 | 0
92 |
93 |
94 | true
95 | PerMonitorV2
96 |
97 |
98 |
99 | MainSource
100 |
101 |
102 |
103 | dfm
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | Cfg_2
123 | Base
124 |
125 |
126 | Base
127 |
128 |
129 | Cfg_1
130 | Base
131 |
132 |
133 |
134 | Delphi.Personality.12
135 | Application
136 |
137 |
138 |
139 | C4DValidateComponentsDemo01.dpr
140 |
141 |
142 |
143 |
144 |
145 | C4DValidateComponentsDemo01.exe
146 | true
147 |
148 |
149 |
150 |
151 | 1
152 |
153 |
154 | Contents\MacOS
155 | 1
156 |
157 |
158 | 0
159 |
160 |
161 |
162 |
163 | classes
164 | 1
165 |
166 |
167 | classes
168 | 1
169 |
170 |
171 |
172 |
173 | res\xml
174 | 1
175 |
176 |
177 | res\xml
178 | 1
179 |
180 |
181 |
182 |
183 | library\lib\armeabi-v7a
184 | 1
185 |
186 |
187 |
188 |
189 | library\lib\armeabi
190 | 1
191 |
192 |
193 | library\lib\armeabi
194 | 1
195 |
196 |
197 |
198 |
199 | library\lib\armeabi-v7a
200 | 1
201 |
202 |
203 |
204 |
205 | library\lib\mips
206 | 1
207 |
208 |
209 | library\lib\mips
210 | 1
211 |
212 |
213 |
214 |
215 | library\lib\armeabi-v7a
216 | 1
217 |
218 |
219 | library\lib\arm64-v8a
220 | 1
221 |
222 |
223 |
224 |
225 | library\lib\armeabi-v7a
226 | 1
227 |
228 |
229 |
230 |
231 | res\drawable
232 | 1
233 |
234 |
235 | res\drawable
236 | 1
237 |
238 |
239 |
240 |
241 | res\values
242 | 1
243 |
244 |
245 | res\values
246 | 1
247 |
248 |
249 |
250 |
251 | res\values-v21
252 | 1
253 |
254 |
255 | res\values-v21
256 | 1
257 |
258 |
259 |
260 |
261 | res\values
262 | 1
263 |
264 |
265 | res\values
266 | 1
267 |
268 |
269 |
270 |
271 | res\drawable
272 | 1
273 |
274 |
275 | res\drawable
276 | 1
277 |
278 |
279 |
280 |
281 | res\drawable-xxhdpi
282 | 1
283 |
284 |
285 | res\drawable-xxhdpi
286 | 1
287 |
288 |
289 |
290 |
291 | res\drawable-ldpi
292 | 1
293 |
294 |
295 | res\drawable-ldpi
296 | 1
297 |
298 |
299 |
300 |
301 | res\drawable-mdpi
302 | 1
303 |
304 |
305 | res\drawable-mdpi
306 | 1
307 |
308 |
309 |
310 |
311 | res\drawable-hdpi
312 | 1
313 |
314 |
315 | res\drawable-hdpi
316 | 1
317 |
318 |
319 |
320 |
321 | res\drawable-xhdpi
322 | 1
323 |
324 |
325 | res\drawable-xhdpi
326 | 1
327 |
328 |
329 |
330 |
331 | res\drawable-mdpi
332 | 1
333 |
334 |
335 | res\drawable-mdpi
336 | 1
337 |
338 |
339 |
340 |
341 | res\drawable-hdpi
342 | 1
343 |
344 |
345 | res\drawable-hdpi
346 | 1
347 |
348 |
349 |
350 |
351 | res\drawable-xhdpi
352 | 1
353 |
354 |
355 | res\drawable-xhdpi
356 | 1
357 |
358 |
359 |
360 |
361 | res\drawable-xxhdpi
362 | 1
363 |
364 |
365 | res\drawable-xxhdpi
366 | 1
367 |
368 |
369 |
370 |
371 | res\drawable-xxxhdpi
372 | 1
373 |
374 |
375 | res\drawable-xxxhdpi
376 | 1
377 |
378 |
379 |
380 |
381 | res\drawable-small
382 | 1
383 |
384 |
385 | res\drawable-small
386 | 1
387 |
388 |
389 |
390 |
391 | res\drawable-normal
392 | 1
393 |
394 |
395 | res\drawable-normal
396 | 1
397 |
398 |
399 |
400 |
401 | res\drawable-large
402 | 1
403 |
404 |
405 | res\drawable-large
406 | 1
407 |
408 |
409 |
410 |
411 | res\drawable-xlarge
412 | 1
413 |
414 |
415 | res\drawable-xlarge
416 | 1
417 |
418 |
419 |
420 |
421 | res\values
422 | 1
423 |
424 |
425 | res\values
426 | 1
427 |
428 |
429 |
430 |
431 | 1
432 |
433 |
434 | Contents\MacOS
435 | 1
436 |
437 |
438 | 0
439 |
440 |
441 |
442 |
443 | Contents\MacOS
444 | 1
445 | .framework
446 |
447 |
448 | Contents\MacOS
449 | 1
450 | .framework
451 |
452 |
453 | 0
454 |
455 |
456 |
457 |
458 | 1
459 | .dylib
460 |
461 |
462 | 1
463 | .dylib
464 |
465 |
466 | 1
467 | .dylib
468 |
469 |
470 | Contents\MacOS
471 | 1
472 | .dylib
473 |
474 |
475 | Contents\MacOS
476 | 1
477 | .dylib
478 |
479 |
480 | 0
481 | .dll;.bpl
482 |
483 |
484 |
485 |
486 | 1
487 | .dylib
488 |
489 |
490 | 1
491 | .dylib
492 |
493 |
494 | 1
495 | .dylib
496 |
497 |
498 | Contents\MacOS
499 | 1
500 | .dylib
501 |
502 |
503 | Contents\MacOS
504 | 1
505 | .dylib
506 |
507 |
508 | 0
509 | .bpl
510 |
511 |
512 |
513 |
514 | 0
515 |
516 |
517 | 0
518 |
519 |
520 | 0
521 |
522 |
523 | 0
524 |
525 |
526 | 0
527 |
528 |
529 | Contents\Resources\StartUp\
530 | 0
531 |
532 |
533 | Contents\Resources\StartUp\
534 | 0
535 |
536 |
537 | 0
538 |
539 |
540 |
541 |
542 | 1
543 |
544 |
545 | 1
546 |
547 |
548 | 1
549 |
550 |
551 |
552 |
553 | 1
554 |
555 |
556 | 1
557 |
558 |
559 | 1
560 |
561 |
562 |
563 |
564 | 1
565 |
566 |
567 | 1
568 |
569 |
570 | 1
571 |
572 |
573 |
574 |
575 | 1
576 |
577 |
578 | 1
579 |
580 |
581 | 1
582 |
583 |
584 |
585 |
586 | 1
587 |
588 |
589 | 1
590 |
591 |
592 | 1
593 |
594 |
595 |
596 |
597 | 1
598 |
599 |
600 | 1
601 |
602 |
603 | 1
604 |
605 |
606 |
607 |
608 | 1
609 |
610 |
611 | 1
612 |
613 |
614 | 1
615 |
616 |
617 |
618 |
619 | 1
620 |
621 |
622 | 1
623 |
624 |
625 | 1
626 |
627 |
628 |
629 |
630 | 1
631 |
632 |
633 | 1
634 |
635 |
636 | 1
637 |
638 |
639 |
640 |
641 | 1
642 |
643 |
644 | 1
645 |
646 |
647 | 1
648 |
649 |
650 |
651 |
652 | 1
653 |
654 |
655 | 1
656 |
657 |
658 | 1
659 |
660 |
661 |
662 |
663 | 1
664 |
665 |
666 | 1
667 |
668 |
669 | 1
670 |
671 |
672 |
673 |
674 | 1
675 |
676 |
677 | 1
678 |
679 |
680 | 1
681 |
682 |
683 |
684 |
685 | 1
686 |
687 |
688 | 1
689 |
690 |
691 | 1
692 |
693 |
694 |
695 |
696 | 1
697 |
698 |
699 | 1
700 |
701 |
702 | 1
703 |
704 |
705 |
706 |
707 | 1
708 |
709 |
710 | 1
711 |
712 |
713 | 1
714 |
715 |
716 |
717 |
718 | 1
719 |
720 |
721 | 1
722 |
723 |
724 | 1
725 |
726 |
727 |
728 |
729 | 1
730 |
731 |
732 | 1
733 |
734 |
735 | 1
736 |
737 |
738 |
739 |
740 | 1
741 |
742 |
743 | 1
744 |
745 |
746 | 1
747 |
748 |
749 |
750 |
751 | 1
752 |
753 |
754 | 1
755 |
756 |
757 | 1
758 |
759 |
760 |
761 |
762 | 1
763 |
764 |
765 | 1
766 |
767 |
768 | 1
769 |
770 |
771 |
772 |
773 | 1
774 |
775 |
776 | 1
777 |
778 |
779 | 1
780 |
781 |
782 |
783 |
784 | 1
785 |
786 |
787 | 1
788 |
789 |
790 | 1
791 |
792 |
793 |
794 |
795 | 1
796 |
797 |
798 | 1
799 |
800 |
801 | 1
802 |
803 |
804 |
805 |
806 | 1
807 |
808 |
809 | 1
810 |
811 |
812 |
813 |
814 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
815 | 1
816 |
817 |
818 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
819 | 1
820 |
821 |
822 |
823 |
824 | 1
825 |
826 |
827 | 1
828 |
829 |
830 |
831 |
832 | ..\
833 | 1
834 |
835 |
836 | ..\
837 | 1
838 |
839 |
840 |
841 |
842 | 1
843 |
844 |
845 | 1
846 |
847 |
848 | 1
849 |
850 |
851 |
852 |
853 | 1
854 |
855 |
856 | 1
857 |
858 |
859 | 1
860 |
861 |
862 |
863 |
864 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
865 | 1
866 |
867 |
868 |
869 |
870 | ..\
871 | 1
872 |
873 |
874 | ..\
875 | 1
876 |
877 |
878 |
879 |
880 | Contents
881 | 1
882 |
883 |
884 | Contents
885 | 1
886 |
887 |
888 |
889 |
890 | Contents\Resources
891 | 1
892 |
893 |
894 | Contents\Resources
895 | 1
896 |
897 |
898 |
899 |
900 | library\lib\armeabi-v7a
901 | 1
902 |
903 |
904 | library\lib\arm64-v8a
905 | 1
906 |
907 |
908 | 1
909 |
910 |
911 | 1
912 |
913 |
914 | 1
915 |
916 |
917 | 1
918 |
919 |
920 | Contents\MacOS
921 | 1
922 |
923 |
924 | Contents\MacOS
925 | 1
926 |
927 |
928 | 0
929 |
930 |
931 |
932 |
933 | library\lib\armeabi-v7a
934 | 1
935 |
936 |
937 |
938 |
939 | 1
940 |
941 |
942 | 1
943 |
944 |
945 |
946 |
947 | Assets
948 | 1
949 |
950 |
951 | Assets
952 | 1
953 |
954 |
955 |
956 |
957 | Assets
958 | 1
959 |
960 |
961 | Assets
962 | 1
963 |
964 |
965 |
966 |
967 |
968 |
969 |
970 |
971 |
972 |
973 |
974 |
975 |
976 |
977 | True
978 | False
979 |
980 |
981 | 12
982 |
983 |
984 |
985 |
986 |
987 |
--------------------------------------------------------------------------------
/Samples/Demo01/C4DValidateComponentsDemo01.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code4Delphi/C4D-Validate-Components/44adcb33bd22a56dc06d1d5562ddaf3e762d5675/Samples/Demo01/C4DValidateComponentsDemo01.res
--------------------------------------------------------------------------------
/Samples/Demo01/Src/Utils/C4D.ValidateComponents.Demo01.Utils.pas:
--------------------------------------------------------------------------------
1 | unit C4D.ValidateComponents.Demo01.Utils;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | Vcl.Graphics,
9 | Vcl.Controls,
10 | Vcl.Forms,
11 | Vcl.Dialogs,
12 | Vcl.StdCtrls,
13 | Vcl.ExtCtrls,
14 | Vcl.ComCtrls,
15 | Vcl.DBCtrls;
16 |
17 | type
18 | TUtils = class
19 | public
20 | class procedure ClearAllFieldsForm(const AForm: TForm);
21 | end;
22 |
23 | implementation
24 |
25 | class procedure TUtils.ClearAllFieldsForm(const AForm: TForm);
26 | var
27 | i: Integer;
28 | LComponent: TComponent;
29 | begin
30 | for i := 0 to Pred(AForm.ComponentCount) do
31 | begin
32 | LComponent := AForm.Components[i];
33 |
34 | if(LComponent is TWinControl)then
35 | if(TWinControl(LComponent).Parent.Name = 'pnConfigBack')then
36 | Continue;
37 |
38 | if(LComponent is TEdit)then
39 | TEdit(LComponent).Clear
40 | else if(LComponent is TMemo)then
41 | TMemo(LComponent).Lines.Clear
42 | else if(LComponent is TComboBox)then
43 | TComboBox(LComponent).ItemIndex := -1
44 | else if(LComponent is TRadioGroup)then
45 | TRadioGroup(LComponent).ItemIndex := -1
46 | else if(LComponent is TCheckBox)then
47 | TCheckBox(LComponent).Checked := False
48 | //DBWARE
49 | else if(LComponent is TDBEdit)then
50 | TDBEdit(LComponent).Field.Clear
51 | else if(LComponent is TDBMemo)then
52 | TDBMemo(LComponent).Field.Clear
53 | else if(LComponent is TDBComboBox)then
54 | TDBComboBox(LComponent).Field.Clear
55 | else if(LComponent is TDBRadioGroup)then
56 | TDBRadioGroup(LComponent).Field.Clear;
57 | end;
58 | end;
59 |
60 | end.
61 |
--------------------------------------------------------------------------------
/Samples/Demo01/Src/View/C4D.ValidateComponents.Demo01.View.Main.dfm:
--------------------------------------------------------------------------------
1 | object C4DValidateComponentsDemo01ViewMain: TC4DValidateComponentsDemo01ViewMain
2 | Left = 0
3 | Top = 0
4 | Caption = 'C4D-validate-components - Demo01'
5 | ClientHeight = 570
6 | ClientWidth = 643
7 | Color = clBtnFace
8 | Font.Charset = DEFAULT_CHARSET
9 | Font.Color = clWindowText
10 | Font.Height = -11
11 | Font.Name = 'Tahoma'
12 | Font.Style = []
13 | OldCreateOrder = False
14 | Position = poScreenCenter
15 | OnCreate = FormCreate
16 | PixelsPerInch = 96
17 | TextHeight = 13
18 | object pnBackAll: TPanel
19 | Left = 0
20 | Top = 0
21 | Width = 643
22 | Height = 570
23 | Align = alClient
24 | BevelOuter = bvNone
25 | TabOrder = 0
26 | object pnButtons: TPanel
27 | Left = 0
28 | Top = 525
29 | Width = 643
30 | Height = 45
31 | Align = alBottom
32 | Padding.Left = 3
33 | Padding.Top = 3
34 | Padding.Right = 3
35 | Padding.Bottom = 3
36 | TabOrder = 0
37 | object btnValidar: TButton
38 | Left = 153
39 | Top = 4
40 | Width = 162
41 | Height = 37
42 | Align = alLeft
43 | Caption = 'Validate'
44 | TabOrder = 0
45 | OnClick = btnValidarClick
46 | end
47 | object btnClearAllFields: TButton
48 | Left = 4
49 | Top = 4
50 | Width = 149
51 | Height = 37
52 | Align = alLeft
53 | Caption = 'Clear all fields'
54 | TabOrder = 1
55 | OnClick = btnClearAllFieldsClick
56 | end
57 | end
58 | object PageControl3: TPageControl
59 | Left = 0
60 | Top = 0
61 | Width = 643
62 | Height = 525
63 | ActivePage = tabDemo
64 | Align = alClient
65 | TabOrder = 1
66 | object tabDemo: TTabSheet
67 | Caption = 'Demo'
68 | object pnDemoBack: TPanel
69 | Left = 0
70 | Top = 0
71 | Width = 635
72 | Height = 497
73 | Align = alClient
74 | TabOrder = 0
75 | object Label1: TLabel
76 | Left = 16
77 | Top = 8
78 | Width = 60
79 | Height = 13
80 | Caption = 'Code (TEdit)'
81 | end
82 | object Label2: TLabel
83 | Left = 149
84 | Top = 8
85 | Width = 62
86 | Height = 13
87 | Caption = 'Name (TEdit)'
88 | end
89 | object Label3: TLabel
90 | Left = 16
91 | Top = 48
92 | Width = 65
93 | Height = 13
94 | Caption = 'Limit $ (TEdit)'
95 | end
96 | object Label4: TLabel
97 | Left = 149
98 | Top = 45
99 | Width = 92
100 | Height = 13
101 | Caption = 'Type (TComboBox)'
102 | end
103 | object Label6: TLabel
104 | Left = 287
105 | Top = 87
106 | Width = 104
107 | Height = 13
108 | Caption = 'Observation (TMemo)'
109 | end
110 | object Label12: TLabel
111 | Left = 440
112 | Top = 45
113 | Width = 23
114 | Height = 13
115 | Caption = 'Date'
116 | end
117 | object edtCode: TEdit
118 | Left = 17
119 | Top = 24
120 | Width = 129
121 | Height = 21
122 | NumbersOnly = True
123 | TabOrder = 0
124 | Text = '10'
125 | end
126 | object edtName: TEdit
127 | Left = 149
128 | Top = 24
129 | Width = 468
130 | Height = 21
131 | TabOrder = 1
132 | Text = 'C'#233'sar Cardoso'
133 | end
134 | object edtLimit: TEdit
135 | Left = 17
136 | Top = 63
137 | Width = 129
138 | Height = 21
139 | TabOrder = 2
140 | Text = '10,00'
141 | end
142 | object cBoxType: TComboBox
143 | Left = 149
144 | Top = 63
145 | Width = 287
146 | Height = 21
147 | Style = csDropDownList
148 | ItemIndex = 0
149 | TabOrder = 3
150 | Text = 'Normal'
151 | Items.Strings = (
152 | 'Normal'
153 | 'Priority')
154 | end
155 | object rdGroupTypePerson: TRadioGroup
156 | Left = 16
157 | Top = 99
158 | Width = 265
159 | Height = 39
160 | Caption = ' Type person (TRadioGroup) '
161 | Columns = 2
162 | ItemIndex = 0
163 | Items.Strings = (
164 | 'Client'
165 | 'Provider')
166 | TabOrder = 4
167 | end
168 | object Memo1: TMemo
169 | Left = 287
170 | Top = 103
171 | Width = 330
172 | Height = 34
173 | Lines.Strings = (
174 | 'Test')
175 | ScrollBars = ssVertical
176 | TabOrder = 5
177 | end
178 | object PageControl1: TPageControl
179 | Left = 16
180 | Top = 147
181 | Width = 601
182 | Height = 131
183 | ActivePage = TabSheet2
184 | TabOrder = 6
185 | object TabSheet1: TTabSheet
186 | Caption = 'TabSheet1'
187 | object Edit2: TEdit
188 | Left = 32
189 | Top = 32
190 | Width = 121
191 | Height = 21
192 | TabOrder = 0
193 | end
194 | end
195 | object TabSheet2: TTabSheet
196 | Caption = 'TabSheet2'
197 | ImageIndex = 1
198 | object PageControl2: TPageControl
199 | Left = 0
200 | Top = 0
201 | Width = 593
202 | Height = 103
203 | ActivePage = TabSheet4
204 | Align = alClient
205 | TabOrder = 0
206 | object TabSheet3: TTabSheet
207 | Caption = 'TabSheet3'
208 | object Edit1: TEdit
209 | Left = 32
210 | Top = 32
211 | Width = 121
212 | Height = 21
213 | TabOrder = 0
214 | end
215 | end
216 | object TabSheet4: TTabSheet
217 | Caption = 'TabSheet4'
218 | ImageIndex = 1
219 | object Panel1: TPanel
220 | Left = 0
221 | Top = 0
222 | Width = 585
223 | Height = 75
224 | Align = alClient
225 | BevelInner = bvLowered
226 | TabOrder = 0
227 | object GroupBox1: TGroupBox
228 | Left = 2
229 | Top = 2
230 | Width = 581
231 | Height = 71
232 | Align = alClient
233 | Caption = 'GroupBox1'
234 | TabOrder = 0
235 | object Label5: TLabel
236 | Left = 11
237 | Top = 15
238 | Width = 121
239 | Height = 13
240 | Caption = 'Test with tabs (TEdit)'
241 | Font.Charset = DEFAULT_CHARSET
242 | Font.Color = clWindowText
243 | Font.Height = -11
244 | Font.Name = 'Tahoma'
245 | Font.Style = [fsBold]
246 | ParentFont = False
247 | end
248 | object edtTestWithTabs: TEdit
249 | Left = 11
250 | Top = 32
251 | Width = 345
252 | Height = 21
253 | TabOrder = 0
254 | Text = 'Coffee'
255 | end
256 | end
257 | end
258 | end
259 | end
260 | end
261 | end
262 | object GroupBox2: TGroupBox
263 | Left = 1
264 | Top = 312
265 | Width = 633
266 | Height = 184
267 | Align = alBottom
268 | Caption = ' Components DBWare '
269 | Font.Charset = DEFAULT_CHARSET
270 | Font.Color = clWindowText
271 | Font.Height = -11
272 | Font.Name = 'Tahoma'
273 | Font.Style = [fsBold]
274 | ParentFont = False
275 | TabOrder = 7
276 | object Label7: TLabel
277 | Left = 15
278 | Top = 19
279 | Width = 73
280 | Height = 13
281 | Caption = 'Code (TDBEdit)'
282 | Color = clBtnFace
283 | Font.Charset = DEFAULT_CHARSET
284 | Font.Color = clWindowText
285 | Font.Height = -11
286 | Font.Name = 'Tahoma'
287 | Font.Style = []
288 | ParentColor = False
289 | ParentFont = False
290 | end
291 | object Label8: TLabel
292 | Left = 149
293 | Top = 19
294 | Width = 75
295 | Height = 13
296 | Caption = 'Name (TDBEdit)'
297 | Color = clBtnFace
298 | Font.Charset = DEFAULT_CHARSET
299 | Font.Color = clWindowText
300 | Font.Height = -11
301 | Font.Name = 'Tahoma'
302 | Font.Style = []
303 | ParentColor = False
304 | ParentFont = False
305 | end
306 | object Label9: TLabel
307 | Left = 15
308 | Top = 70
309 | Width = 69
310 | Height = 13
311 | Caption = 'Limit (TDBEdit)'
312 | Color = clBtnFace
313 | FocusControl = edtDBLimit
314 | Font.Charset = DEFAULT_CHARSET
315 | Font.Color = clWindowText
316 | Font.Height = -11
317 | Font.Name = 'Tahoma'
318 | Font.Style = []
319 | ParentColor = False
320 | ParentFont = False
321 | end
322 | object Label10: TLabel
323 | Left = 149
324 | Top = 70
325 | Width = 99
326 | Height = 13
327 | Caption = 'Type (DBComboBox)'
328 | Color = clBtnFace
329 | Font.Charset = DEFAULT_CHARSET
330 | Font.Color = clWindowText
331 | Font.Height = -11
332 | Font.Name = 'Tahoma'
333 | Font.Style = []
334 | ParentColor = False
335 | ParentFont = False
336 | end
337 | object Label11: TLabel
338 | Left = 247
339 | Top = 114
340 | Width = 117
341 | Height = 13
342 | Caption = 'Observation (TDBMemo)'
343 | Color = clBtnFace
344 | Font.Charset = DEFAULT_CHARSET
345 | Font.Color = clWindowText
346 | Font.Height = -11
347 | Font.Name = 'Tahoma'
348 | Font.Style = []
349 | ParentColor = False
350 | ParentFont = False
351 | end
352 | object edtDBCode: TDBEdit
353 | Left = 17
354 | Top = 37
355 | Width = 129
356 | Height = 21
357 | DataField = 'Id'
358 | DataSource = DataSource1
359 | Font.Charset = DEFAULT_CHARSET
360 | Font.Color = clWindowText
361 | Font.Height = -11
362 | Font.Name = 'Tahoma'
363 | Font.Style = []
364 | ParentFont = False
365 | TabOrder = 0
366 | end
367 | object edtDBName: TDBEdit
368 | Left = 149
369 | Top = 37
370 | Width = 467
371 | Height = 21
372 | DataField = 'Name'
373 | DataSource = DataSource1
374 | Font.Charset = DEFAULT_CHARSET
375 | Font.Color = clWindowText
376 | Font.Height = -11
377 | Font.Name = 'Tahoma'
378 | Font.Style = []
379 | ParentFont = False
380 | TabOrder = 1
381 | end
382 | object edtDBLimit: TDBEdit
383 | Left = 17
384 | Top = 86
385 | Width = 129
386 | Height = 21
387 | DataField = 'Limit'
388 | DataSource = DataSource1
389 | Font.Charset = DEFAULT_CHARSET
390 | Font.Color = clWindowText
391 | Font.Height = -11
392 | Font.Name = 'Tahoma'
393 | Font.Style = []
394 | ParentFont = False
395 | TabOrder = 2
396 | end
397 | object cBoxDBType: TDBComboBox
398 | Left = 149
399 | Top = 86
400 | Width = 467
401 | Height = 21
402 | DataField = 'Type'
403 | DataSource = DataSource1
404 | Font.Charset = DEFAULT_CHARSET
405 | Font.Color = clWindowText
406 | Font.Height = -11
407 | Font.Name = 'Tahoma'
408 | Font.Style = []
409 | Items.Strings = (
410 | 'Normal'
411 | 'Priority')
412 | ParentFont = False
413 | TabOrder = 3
414 | end
415 | object rdGroupDBTypePerson: TDBRadioGroup
416 | Left = 15
417 | Top = 115
418 | Width = 224
419 | Height = 49
420 | Caption = ' Tipe Person (DBRadioGroup)'
421 | Color = clBtnFace
422 | Columns = 2
423 | DataField = 'TypePerson'
424 | DataSource = DataSource1
425 | Font.Charset = DEFAULT_CHARSET
426 | Font.Color = clWindowText
427 | Font.Height = -11
428 | Font.Name = 'Tahoma'
429 | Font.Style = []
430 | Items.Strings = (
431 | 'Client'
432 | 'Provider')
433 | ParentColor = False
434 | ParentFont = False
435 | TabOrder = 4
436 | Values.Strings = (
437 | '1'
438 | '2')
439 | end
440 | object DBMemo1: TDBMemo
441 | Left = 245
442 | Top = 129
443 | Width = 371
444 | Height = 34
445 | DataField = 'Observation'
446 | DataSource = DataSource1
447 | Font.Charset = DEFAULT_CHARSET
448 | Font.Color = clWindowText
449 | Font.Height = -11
450 | Font.Name = 'Tahoma'
451 | Font.Style = []
452 | ParentFont = False
453 | TabOrder = 5
454 | end
455 | end
456 | object DateTimePicker1: TDateTimePicker
457 | Left = 440
458 | Top = 62
459 | Width = 177
460 | Height = 21
461 | Date = 45262.000000000000000000
462 | Time = 0.453400254627922600
463 | TabOrder = 8
464 | end
465 | end
466 | end
467 | object tabConfig: TTabSheet
468 | Caption = 'Config (optional)'
469 | ImageIndex = 1
470 | object pnConfigBack: TPanel
471 | Left = 0
472 | Top = 0
473 | Width = 635
474 | Height = 497
475 | Align = alClient
476 | BevelOuter = bvNone
477 | ParentBackground = False
478 | TabOrder = 0
479 | object Label13: TLabel
480 | Left = 16
481 | Top = 16
482 | Width = 170
483 | Height = 13
484 | Caption = 'Language mensages (default pt-br)'
485 | end
486 | object ckConfigDisplayComponentNameIfNotFieldDisplay: TCheckBox
487 | Left = 16
488 | Top = 59
489 | Width = 457
490 | Height = 17
491 | Hint =
492 | 'Exibir o nome do componente se o Custom Attribute FieldDisplay n' +
493 | #227'o for informado (padr'#227'o Sim)'
494 | Caption =
495 | 'Display component name if FieldDisplay Custom Attributes are not' +
496 | ' provided (default True)'
497 | Checked = True
498 | ParentShowHint = False
499 | ShowHint = True
500 | State = cbChecked
501 | TabOrder = 0
502 | end
503 | object cBoxConfigLanguage: TComboBox
504 | Left = 16
505 | Top = 32
506 | Width = 201
507 | Height = 21
508 | Style = csDropDownList
509 | ItemIndex = 0
510 | TabOrder = 1
511 | Text = 'Portugues Brazil (pt-br)'
512 | Items.Strings = (
513 | 'Portugues Brazil (pt-br)'
514 | 'Ingles (en-us)')
515 | end
516 | object bntConfigSave: TButton
517 | Left = 16
518 | Top = 96
519 | Width = 113
520 | Height = 25
521 | Caption = 'Save'
522 | TabOrder = 2
523 | OnClick = bntConfigSaveClick
524 | end
525 | object ckConfigShowOneErrorAtATime: TCheckBox
526 | Left = 16
527 | Top = 75
528 | Width = 217
529 | Height = 17
530 | Hint = 'Mostrar um erro por cada vez (padr'#227'o sim)'
531 | Caption = 'Show one error at a time (default True)'
532 | Checked = True
533 | ParentShowHint = False
534 | ShowHint = True
535 | State = cbChecked
536 | TabOrder = 3
537 | end
538 | end
539 | end
540 | end
541 | end
542 | object ClientDataSet1: TClientDataSet
543 | PersistDataPacket.Data = {
544 | B20000009619E0BD010000001800000007000000000003000000B20002496404
545 | 00010000000000044E616D650100490000000100055749445448020002006400
546 | 0A54797065506572736F6E04000100000000000B4F62736572766174696F6E01
547 | 00490000000100055749445448020002006400054C696D697408000400000000
548 | 0005436865636B01004900000001000557494454480200020005000454797065
549 | 01004900000001000557494454480200020032000000}
550 | Active = True
551 | Aggregates = <>
552 | Params = <>
553 | Left = 540
554 | Top = 351
555 | object ClientDataSet1Id: TIntegerField
556 | FieldName = 'Id'
557 | end
558 | object ClientDataSet1Name: TStringField
559 | FieldName = 'Name'
560 | Size = 100
561 | end
562 | object ClientDataSet1TypePerson: TIntegerField
563 | FieldName = 'TypePerson'
564 | end
565 | object ClientDataSet1Observation: TStringField
566 | FieldName = 'Observation'
567 | Size = 100
568 | end
569 | object ClientDataSet1Limit: TFloatField
570 | FieldName = 'Limit'
571 | DisplayFormat = ',,0.00'
572 | end
573 | object ClientDataSet1Check: TStringField
574 | FieldName = 'Check'
575 | Size = 5
576 | end
577 | object ClientDataSet1Type: TStringField
578 | FieldName = 'Type'
579 | Size = 50
580 | end
581 | end
582 | object DataSource1: TDataSource
583 | DataSet = ClientDataSet1
584 | Left = 539
585 | Top = 394
586 | end
587 | end
588 |
--------------------------------------------------------------------------------
/Samples/Demo01/Src/View/C4D.ValidateComponents.Demo01.View.Main.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code4Delphi/C4D-Validate-Components/44adcb33bd22a56dc06d1d5562ddaf3e762d5675/Samples/Demo01/Src/View/C4D.ValidateComponents.Demo01.View.Main.pas
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Components.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Components;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | Vcl.StdCtrls,
9 | Vcl.ExtCtrls,
10 | Vcl.Controls,
11 | Vcl.ComCtrls,
12 | Vcl.Forms,
13 | Vcl.DBCtrls;
14 |
15 | type
16 | TC4DValidateComponentsComponents = class
17 | private
18 | public
19 | class function GetTextFromComponent(const AComponent: TComponent): string;
20 | class procedure SetFocu(const AComponent: TComponent);
21 | end;
22 |
23 | implementation
24 |
25 | uses
26 | C4D.Validate.Components.Language;
27 |
28 | class function TC4DValidateComponentsComponents.GetTextFromComponent(const AComponent: TComponent): string;
29 | begin
30 | Result := '';
31 | try
32 | if(AComponent is TEdit)then
33 | Exit(TEdit(AComponent).Text);
34 |
35 | if(AComponent is TMemo)then
36 | Exit(TMemo(AComponent).Text);
37 |
38 | if(AComponent is TComboBox)then
39 | Exit(TComboBox(AComponent).Text);
40 |
41 | if(AComponent is TRadioGroup)then
42 | begin
43 | if(TRadioGroup(AComponent).ItemIndex >= 0)then
44 | Result := TRadioGroup(AComponent).Items[TRadioGroup(AComponent).ItemIndex];
45 |
46 | Exit;
47 | end;
48 |
49 | if(AComponent is TDateTimePicker)then
50 | Exit(DateToStr(TDateTimePicker(AComponent).Date));
51 |
52 | //DBWARE
53 | if(AComponent is TDBEdit)then
54 | Exit(TDBEdit(AComponent).Field.AsString);
55 |
56 | if(AComponent is TDBMemo)then
57 | Exit(TDBMemo(AComponent).Field.AsString);
58 |
59 | if(AComponent is TDBComboBox)then
60 | Exit(TDBComboBox(AComponent).Field.AsString);
61 |
62 | if(AComponent is TDBRadioGroup)then
63 | begin
64 | if(TDBRadioGroup(AComponent).ItemIndex >= 0)then
65 | Result := TDBRadioGroup(AComponent).Items[TDBRadioGroup(AComponent).ItemIndex];
66 |
67 | Exit;
68 | end;
69 |
70 | raise Exception.Create(TLanguage.ComponentNotSuported + Format(' [%s]', [ AComponent.Name]));
71 | finally
72 | Result := Result.Trim;
73 | end;
74 | end;
75 |
76 | class procedure TC4DValidateComponentsComponents.SetFocu(const AComponent: TComponent);
77 | var
78 | LParent: TComponent;
79 | begin
80 | if not(AComponent is TWinControl)then
81 | Exit;
82 |
83 | LParent := TWinControl(AComponent).Parent;
84 | while(LParent <> nil)and(LParent.ClassParent <> TForm)do
85 | begin
86 | if(LParent is TTabSheet)then
87 | if(not TTabSheet(LParent).Showing)then
88 | TTabSheet(LParent).Show;
89 | LParent := TWinControl(LParent).Parent;
90 | end;
91 |
92 | if(TWinControl(AComponent).CanFocus)then
93 | TWinControl(AComponent).SetFocus;
94 | end;
95 |
96 | end.
97 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Config.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Config;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | C4D.Validate.Components.Types;
8 |
9 | type
10 | TC4DValidateComponentsConfig = class
11 | private
12 | FLanguage: TLanguageDefault;
13 | FDisplayComponentNameIfNotFieldDisplay: Boolean;
14 | FShowOneErrorAtATime: Boolean;
15 | constructor Create;
16 | public
17 | class function GetInstance: TC4DValidateComponentsConfig;
18 | function Language: TLanguageDefault; overload;
19 | function Language(const Value: TLanguageDefault): TC4DValidateComponentsConfig; overload;
20 | function DisplayComponentNameIfNotFieldDisplay: Boolean; overload;
21 | function DisplayComponentNameIfNotFieldDisplay(const Value: Boolean): TC4DValidateComponentsConfig; overload;
22 | function ShowOneErrorAtATime: Boolean; overload;
23 | function ShowOneErrorAtATime(const Value: Boolean): TC4DValidateComponentsConfig; overload;
24 | end;
25 |
26 | implementation
27 |
28 | var
29 | Instance: TC4DValidateComponentsConfig;
30 |
31 | constructor TC4DValidateComponentsConfig.Create;
32 | begin
33 | FLanguage := TLanguageDefault.ptBR;
34 | FDisplayComponentNameIfNotFieldDisplay := True;
35 | FShowOneErrorAtATime := True;
36 | end;
37 |
38 | class function TC4DValidateComponentsConfig.GetInstance: TC4DValidateComponentsConfig;
39 | begin
40 | if(not Assigned(Instance))then
41 | Instance := Self.Create;
42 | Result := Instance;
43 | end;
44 |
45 | function TC4DValidateComponentsConfig.Language: TLanguageDefault;
46 | begin
47 | Result := FLanguage;
48 | end;
49 |
50 | function TC4DValidateComponentsConfig.Language(const Value: TLanguageDefault): TC4DValidateComponentsConfig;
51 | begin
52 | Result := Self;
53 | FLanguage := Value;
54 | end;
55 |
56 | function TC4DValidateComponentsConfig.DisplayComponentNameIfNotFieldDisplay: Boolean;
57 | begin
58 | Result := FDisplayComponentNameIfNotFieldDisplay;
59 | end;
60 |
61 | function TC4DValidateComponentsConfig.DisplayComponentNameIfNotFieldDisplay(const Value: Boolean): TC4DValidateComponentsConfig;
62 | begin
63 | Result := Self;
64 | FDisplayComponentNameIfNotFieldDisplay := Value;
65 | end;
66 |
67 | function TC4DValidateComponentsConfig.ShowOneErrorAtATime: Boolean;
68 | begin
69 | Result := FShowOneErrorAtATime;
70 | end;
71 |
72 | function TC4DValidateComponentsConfig.ShowOneErrorAtATime(const Value: Boolean): TC4DValidateComponentsConfig;
73 | begin
74 | Result := Self;
75 | FShowOneErrorAtATime := Value;
76 | end;
77 |
78 | initialization
79 |
80 | finalization
81 | if(Assigned(Instance))then
82 | FreeAndNil(Instance);
83 |
84 | end.
85 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Consts.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code4Delphi/C4D-Validate-Components/44adcb33bd22a56dc06d1d5562ddaf3e762d5675/Src/C4D.Validate.Components.Consts.pas
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Errors.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Errors;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | C4D.Validate.Components.ListPair;
9 |
10 | type
11 | TErros = class
12 | private
13 | FListPairErros: TListPairStr;
14 | constructor Create;
15 | public
16 | class function GetInstance: TErros;
17 | destructor Destroy; override;
18 | procedure Clear;
19 | procedure Add(const AComponentName, AMsg: string);
20 | function GetMessages: string;
21 | function HasErros: Boolean;
22 | function Count: Integer;
23 | function GetNameFirstComponent: string;
24 | end;
25 |
26 | implementation
27 |
28 | var
29 | Instance: TErros;
30 |
31 | class function TErros.GetInstance: TErros;
32 | begin
33 | if(not Assigned(Instance))then
34 | Instance := Self.Create;
35 | Result := Instance;
36 | end;
37 |
38 | constructor TErros.Create;
39 | begin
40 | FListPairErros := TListPairStr.Create;
41 | end;
42 |
43 | destructor TErros.Destroy;
44 | begin
45 | FListPairErros.Free;
46 | inherited;
47 | end;
48 |
49 | procedure TErros.Clear;
50 | begin
51 | FListPairErros.Clear;
52 | end;
53 |
54 | procedure TErros.Add(const AComponentName, AMsg: string);
55 | begin
56 | FListPairErros.Add(AComponentName, AMsg);
57 | end;
58 |
59 | function TErros.GetMessages: string;
60 | begin
61 | Result := FListPairErros.GetStringsValues;
62 | end;
63 |
64 | function TErros.HasErros: Boolean;
65 | begin
66 | Result := FListPairErros.Count > 0;
67 | end;
68 |
69 | function TErros.Count: Integer;
70 | begin
71 | Result := FListPairErros.Count;
72 | end;
73 |
74 | function TErros.GetNameFirstComponent: string;
75 | begin
76 | Result := '';
77 |
78 | if(FListPairErros.Count > 0)then
79 | Result := FListPairErros.Items[0].Key;
80 | end;
81 |
82 | initialization
83 |
84 | finalization
85 | if(Assigned(Instance))then
86 | FreeAndNil(Instance);
87 |
88 | end.
89 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.FieldDisplay.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.FieldDisplay;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils;
7 |
8 | type
9 | FieldDisplay = class(TCustomAttribute)
10 | private
11 | FDisplay: String;
12 | public
13 | constructor Create(const ADisplay: String);
14 | property Display: String read FDisplay;
15 | end;
16 |
17 | implementation
18 |
19 | constructor FieldDisplay.Create(const ADisplay: String);
20 | begin
21 | FDisplay := ADisplay;
22 | end;
23 |
24 | end.
25 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Helpers.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Helpers;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.RTTI;
8 |
9 | type
10 | TRttiFieldyHelper = class helper for TRttiField
11 | private
12 | function GetCustomAttribute: T;
13 | public
14 | function GetFieldDisplay: string;
15 | function FormatMsg(const AMsg: string): string;
16 | end;
17 |
18 | implementation
19 |
20 | uses
21 | C4D.Validate.Components.FieldDisplay,
22 | C4D.Validate.Components.Consts,
23 | C4D.Validate.Components.Config;
24 |
25 | function TRttiFieldyHelper.GetCustomAttribute: T;
26 | var
27 | LCustomAttribute: TCustomAttribute;
28 | begin
29 | Result := nil;
30 | for LCustomAttribute in GetAttributes do
31 | if LCustomAttribute is T then
32 | Exit((LCustomAttribute as T));
33 | end;
34 |
35 | function TRttiFieldyHelper.GetFieldDisplay: string;
36 | var
37 | LFieldDisplay: FieldDisplay;
38 | begin
39 | Result := '';
40 | if(TC4DValidateComponentsConfig.GetInstance.DisplayComponentNameIfNotFieldDisplay)then
41 | Result := Self.Name;
42 |
43 | LFieldDisplay := GetCustomAttribute;
44 | if(LFieldDisplay <> nil)then
45 | Result := LFieldDisplay.Display;
46 | end;
47 |
48 | function TRttiFieldyHelper.FormatMsg(const AMsg: string): string;
49 | var
50 | LFieldDisplay: string;
51 | begin
52 | Result := AMsg;
53 | LFieldDisplay := Self.GetFieldDisplay;
54 |
55 | if(pos(TAG_FIELD_DISPLAY, AMsg) > 0)then
56 | Result := AMsg.Replace(TAG_FIELD_DISPLAY, LFieldDisplay, [rfReplaceAll, rfIgnoreCase])
57 | else if(not LFieldDisplay.Trim.IsEmpty)then
58 | Result := AMsg + Format(' [%s]', [Self.GetFieldDisplay]) ;
59 | end;
60 |
61 |
62 | end.
63 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Language.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Code4Delphi/C4D-Validate-Components/44adcb33bd22a56dc06d1d5562ddaf3e762d5675/Src/C4D.Validate.Components.Language.pas
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Length.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Length;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | System.RTTI;
9 |
10 | type
11 | Length = class(TCustomAttribute)
12 | private
13 | FMinLength: Integer;
14 | FMaxLength: Integer;
15 | FMsg: string;
16 | function GetMsg: string;
17 | public
18 | constructor Create(const AMinLength: Integer); overload;
19 | constructor Create(const AMinLength, AMaxLength: Integer); overload;
20 | constructor Create(const AMinLength: Integer; const AMsg: string); overload;
21 | constructor Create(const AMinLength, AMaxLength: Integer; const AMsg: string); overload;
22 | procedure Validar(const ARttiField: TRttiField; const AObject: TObject);
23 | end;
24 |
25 | implementation
26 |
27 | uses
28 | C4D.Validate.Components.Helpers,
29 | C4D.Validate.Components.Components,
30 | C4D.Validate.Components.Consts,
31 | C4D.Validate.Components.Language,
32 | C4D.Validate.Components.Errors;
33 |
34 | constructor Length.Create(const AMinLength: Integer);
35 | begin
36 | Self.Create(AMinLength, 0, '');
37 | end;
38 |
39 | constructor Length.Create(const AMinLength, AMaxLength: Integer);
40 | begin
41 | Self.Create(AMinLength, AMaxLength, '');
42 | end;
43 |
44 | constructor Length.Create(const AMinLength: Integer; const AMsg: string);
45 | begin
46 | Self.Create(AMinLength, 0, AMsg);
47 | end;
48 |
49 | constructor Length.Create(const AMinLength, AMaxLength: Integer; const AMsg: string);
50 | begin
51 | FMinLength := AMinLength;
52 | FMaxLength := AMaxLength;
53 |
54 | if(not AMsg.Trim.IsEmpty)then
55 | FMsg := AMsg.Trim
56 | else if(FMinLength > 0)and(FMaxLength > 0)then
57 | FMsg := TLanguage.MsgDefaultLength
58 | else if(FMinLength > 0)then
59 | FMsg := TLanguage.MsgDefaultLengthMin
60 | else if(FMaxLength > 0)then
61 | FMsg := TLanguage.MsgDefaultLengthMax;
62 | end;
63 |
64 | function Length.GetMsg: string;
65 | begin
66 | Result := FMsg
67 | .Replace(TAG_MIN, FMinLength.ToString, [rfReplaceAll, rfIgnoreCase])
68 | .Replace(TAG_MAX, FMaxLength.ToString, [rfReplaceAll, rfIgnoreCase]);
69 | end;
70 |
71 | procedure Length.Validar(const ARttiField: TRttiField; const AObject: TObject);
72 | var
73 | LComponent: TComponent;
74 | LText: string;
75 | LLength: Integer;
76 | begin
77 | LComponent := (ARttiField.GetValue(AObject).AsObject as TComponent);
78 | LText := TC4DValidateComponentsComponents.GetTextFromComponent(LComponent);
79 | LLength := LText.Length;
80 | if(LLength < FMinLength)or((FMaxLength > 0)and(LLength > FMaxLength))then
81 | TErros.GetInstance.Add(LComponent.Name, ARttiField.FormatMsg(Self.GetMsg));
82 | end;
83 |
84 | end.
85 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.ListPair.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.ListPair;
2 |
3 | interface
4 |
5 | uses
6 | System.Types,
7 | System.SysUtils,
8 | System.Classes,
9 | System.Generics.Defaults,
10 | System.Generics.Collections;
11 |
12 | type
13 | TListPair = class(TList>)
14 | protected
15 | FKeyComparer: IComparer;
16 | FValueComparer: IComparer;
17 | function GetValue(Key: TKey): TValue;
18 | procedure SetValue(Key: TKey; const Value: TValue);
19 | function ComparePair(const Left, Right: TPair): Integer;
20 | public
21 | constructor Create; overload;
22 | procedure Add(const AKey: TKey; const aValue: TValue); overload;
23 | function IndexOfKey(const AKey: TKey): Integer;
24 | function ContainsKey(const AKey: TKey): Boolean; inline;
25 | property Values[Key: TKey]: TValue read GetValue write SetValue;
26 | end;
27 |
28 | TListPairStr = class(TListPair);
29 |
30 | TListPairStrHelper = class helper for TListPairStr
31 | procedure FillStringsWithValues(const AStrings: TStrings);
32 | function GetStringsValues: string;
33 | end;
34 |
35 | implementation
36 |
37 | constructor TListPair.Create;
38 | begin
39 | if(FKeyComparer = nil)then
40 | FKeyComparer := TComparer.Default;
41 | if(FValueComparer = nil)then
42 | FValueComparer := TComparer.Default;
43 | inherited Create(TDelegatedComparer >.Create(ComparePair));
44 | end;
45 |
46 | function TListPair.ComparePair(const Left, Right: TPair): Integer;
47 | begin
48 | Result := FKeyComparer.Compare(Left.Key, Right.Key);
49 | if(Result = 0)then
50 | Result := FValueComparer.Compare(Left.Value, Right.Value);
51 | end;
52 |
53 | function TListPair.IndexOfKey(const AKey: TKey): Integer;
54 | var
55 | i: Integer;
56 | begin
57 | Result := -1;
58 | for i := 0 to Count - 1 do
59 | begin
60 | if(FKeyComparer.Compare(Items[i].Key, AKey) = 0)then
61 | begin
62 | Result := i;
63 | break;
64 | end;
65 | end;
66 | end;
67 |
68 | function TListPair.ContainsKey(const AKey: TKey): Boolean;
69 | begin
70 | Result := IndexOfKey(AKey) >= 0;
71 | end;
72 |
73 | function TListPair.GetValue(Key: TKey): TValue;
74 | var
75 | i: Integer;
76 | begin
77 | i := IndexOfKey(Key);
78 | if(i >= 0)then
79 | Result := Items[i].Value
80 | else
81 | Result := default(TValue);
82 | end;
83 |
84 | procedure TListPair.Add(const AKey: TKey; const aValue: TValue);
85 | begin
86 | SetValue(AKey, aValue);
87 | end;
88 |
89 | procedure TListPair.SetValue(Key: TKey; const Value: TValue);
90 | begin
91 | inherited Add(TPair.Create(Key, Value));
92 | end;
93 |
94 | { TListPairStrHelper }
95 | procedure TListPairStrHelper.FillStringsWithValues(const AStrings: TStrings);
96 | var
97 | LPairErro: TPair;
98 | begin
99 | if(Self.Count > 0)then
100 | for LPairErro in Self do
101 | AStrings.Add('* ' + LPairErro.Value);
102 | end;
103 |
104 | function TListPairStrHelper.GetStringsValues: string;
105 | var
106 | LPairErro: TPair;
107 | begin
108 | Result := '';
109 | if(Self.Count > 0)then
110 | for LPairErro in Self do
111 | Result := Result + '* ' + LPairErro.Value + sLineBreak;
112 | end;
113 |
114 | end.
115 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.MinMaxDate.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.MinMaxDate;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | System.RTTI;
9 |
10 | type
11 | MinMaxDate = class(TCustomAttribute)
12 | private
13 | FMinDate: TDate;
14 | FMaxDate: TDate;
15 | FMsg: string;
16 | function GetMsg: string;
17 | public
18 | constructor Create(const AMinDate: string); overload;
19 | constructor Create(const AMinDate, AMaxDate: string); overload;
20 | constructor Create(const AMinDate, AMaxDate, AMsg: string); overload;
21 | procedure Validar(const ARttiField: TRttiField; const AObject: TObject);
22 | end;
23 |
24 | implementation
25 |
26 | uses
27 | C4D.Validate.Components.Helpers,
28 | C4D.Validate.Components.Components,
29 | C4D.Validate.Components.Consts,
30 | C4D.Validate.Components.Language,
31 | C4D.Validate.Components.Errors;
32 |
33 | constructor MinMaxDate.Create(const AMinDate: string);
34 | begin
35 | Self.Create(AMinDate, '', '');
36 | end;
37 |
38 | constructor MinMaxDate.Create(const AMinDate, AMaxDate: string);
39 | begin
40 | Self.Create('', AMaxDate, '');
41 | end;
42 |
43 | constructor MinMaxDate.Create(const AMinDate, AMaxDate, AMsg: string);
44 | begin
45 | FMinDate := StrToDateDef(AMinDate, 0);
46 | FMaxDate := StrToDateDef(AMaxDate, 0);
47 |
48 | if(not AMsg.Trim.IsEmpty)then
49 | FMsg := AMsg.Trim
50 | else if(FMinDate > 0)and(FMaxDate > 0)then
51 | FMsg := TLanguage.MsgDefaultDate
52 | else if(FMinDate > 0)then
53 | FMsg := TLanguage.MsgDefaultDateMin
54 | else if(FMaxDate > 0)then
55 | FMsg := TLanguage.MsgDefaultDateMax;
56 | end;
57 |
58 | function MinMaxDate.GetMsg: string;
59 | begin
60 | Result := FMsg
61 | .Replace(TAG_MIN, DateToStr(FMinDate), [rfReplaceAll, rfIgnoreCase])
62 | .Replace(TAG_MAX, DateToStr(FMaxDate), [rfReplaceAll, rfIgnoreCase]);
63 | end;
64 |
65 | procedure MinMaxDate.Validar(const ARttiField: TRttiField; const AObject: TObject);
66 | var
67 | LComponent: TComponent;
68 | LText: string;
69 | LDate: TDate;
70 | begin
71 | LComponent := (ARttiField.GetValue(AObject).AsObject as TComponent);
72 | LText := TC4DValidateComponentsComponents.GetTextFromComponent(LComponent);
73 | LDate := StrToDateDef(LText, 0);
74 | if(LDate < FMinDate)or((FMaxDate > 0)and(LDate > FMaxDate))then
75 | TErros.GetInstance.Add(LComponent.Name, ARttiField.FormatMsg(Self.GetMsg));
76 | end;
77 |
78 | end.
79 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.MinMaxValue.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.MinMaxValue;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | System.RTTI;
9 |
10 | type
11 | MinMaxValue = class(TCustomAttribute)
12 | private
13 | FMinValue: Integer;
14 | FMaxValue: Integer;
15 | FMsg: string;
16 | function GetMsg: string;
17 | public
18 | constructor Create(const AMinValue: Integer); overload;
19 | constructor Create(const AMinValue, AMaxValue: Integer); overload;
20 | constructor Create(const AMinValue: Integer; const AMsg: string); overload;
21 | constructor Create(const AMinValue, AMaxValue: Integer; const AMsg: string); overload;
22 | procedure Validar(const ARttiField: TRttiField; const AObject: TObject);
23 | end;
24 |
25 | implementation
26 |
27 | uses
28 | C4D.Validate.Components.Helpers,
29 | C4D.Validate.Components.Components,
30 | C4D.Validate.Components.Consts,
31 | C4D.Validate.Components.Language,
32 | C4D.Validate.Components.Errors;
33 |
34 | constructor MinMaxValue.Create(const AMinValue: Integer);
35 | begin
36 | Self.Create(AMinValue, 0, '');
37 | end;
38 |
39 | constructor MinMaxValue.Create(const AMinValue, AMaxValue: Integer);
40 | begin
41 | Self.Create(AMinValue, AMaxValue, '');
42 | end;
43 |
44 | constructor MinMaxValue.Create(const AMinValue: Integer; const AMsg: string);
45 | begin
46 | Self.Create(AMinValue, 0, AMsg);
47 | end;
48 |
49 | constructor MinMaxValue.Create(const AMinValue, AMaxValue: Integer; const AMsg: string);
50 | begin
51 | FMinValue := AMinValue;
52 | FMaxValue := AMaxValue;
53 |
54 | if(not AMsg.Trim.IsEmpty)then
55 | FMsg := AMsg.Trim
56 | else if(FMinValue > 0)and(FMaxValue > 0)then
57 | FMsg := TLanguage.MsgDefaultValue
58 | else if(FMinValue > 0)then
59 | FMsg := TLanguage.MsgDefaultValueMin
60 | else if(FMaxValue > 0)then
61 | FMsg := TLanguage.MsgDefaultValueMax;
62 | end;
63 |
64 | function MinMaxValue.GetMsg: string;
65 | begin
66 | Result := FMsg
67 | .Replace(TAG_MIN, FMinValue.ToString, [rfReplaceAll, rfIgnoreCase])
68 | .Replace(TAG_MAX, FMaxValue.ToString, [rfReplaceAll, rfIgnoreCase]);
69 | end;
70 |
71 | procedure MinMaxValue.Validar(const ARttiField: TRttiField; const AObject: TObject);
72 | var
73 | LComponent: TComponent;
74 | LText: string;
75 | LValue: Double;
76 | begin
77 | LComponent := (ARttiField.GetValue(AObject).AsObject as TComponent);
78 | LText := TC4DValidateComponentsComponents.GetTextFromComponent(LComponent);
79 | LValue := StrToFloatDef(LText, 0);
80 | if(LValue < FMinValue)or((FMaxValue > 0)and(LValue > FMaxValue))then
81 | TErros.GetInstance.Add(LComponent.Name, ARttiField.FormatMsg(Self.GetMsg));
82 | end;
83 |
84 | end.
85 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.NotEmpty.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.NotEmpty;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | System.RTTI;
9 |
10 | type
11 | NotEmpty = class(TCustomAttribute)
12 | private
13 | FMsg: string;
14 | public
15 | constructor Create; overload;
16 | constructor Create(const AMsg: string); overload;
17 | procedure Validar(const ARttiField: TRttiField; const AObject: TObject);
18 | end;
19 |
20 | implementation
21 |
22 | uses
23 | C4D.Validate.Components.Helpers,
24 | C4D.Validate.Components.Components,
25 | C4D.Validate.Components.Language,
26 | C4D.Validate.Components.Errors;
27 |
28 | constructor NotEmpty.Create;
29 | begin
30 | FMsg := TLanguage.MsgDefaultNotEmpty;
31 | end;
32 |
33 | constructor NotEmpty.Create(const AMsg: string);
34 | begin
35 | FMsg := AMsg;
36 | end;
37 |
38 | procedure NotEmpty.Validar(const ARttiField: TRttiField; const AObject: TObject);
39 | var
40 | LComponent: TComponent;
41 | LText: string;
42 | begin
43 | LComponent := (ARttiField.GetValue(AObject).AsObject as TComponent);
44 | LText := TC4DValidateComponentsComponents.GetTextFromComponent(LComponent);
45 |
46 | if(LText.Trim.IsEmpty)then
47 | TErros.GetInstance.Add(LComponent.Name, ARttiField.FormatMsg(FMsg));
48 | end;
49 |
50 | end.
51 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.SetFocus.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.SetFocus;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.RTTI,
8 | System.Classes,
9 | Vcl.Forms,
10 | Vcl.Controls,
11 | Vcl.ComCtrls;
12 |
13 | type
14 | TRttiSetFocus = class
15 | private
16 | class procedure SetFocusComponent(const AWinControl: TWinControl);
17 | public
18 | class procedure SetFocusComponentName(const AForm: TForm; const AComponentName: string);
19 | end;
20 |
21 | implementation
22 |
23 | class procedure TRttiSetFocus.SetFocusComponentName(const AForm: TForm; const AComponentName: string);
24 | var
25 | LComponent: TComponent;
26 | begin
27 | LComponent := AForm.FindComponent(AComponentName);
28 | if(LComponent is TWinControl)then
29 | SetFocusComponent(TWinControl(LComponent));
30 | end;
31 |
32 | class procedure TRttiSetFocus.SetFocusComponent(const AWinControl: TWinControl);
33 | var
34 | LParent: TComponent;
35 | begin
36 | LParent := TWinControl(AWinControl).Parent;
37 | while(LParent.ClassParent <> TForm)do
38 | begin
39 | if(LParent is TTabSheet)then
40 | if(not TTabSheet(LParent).Showing)then
41 | TTabSheet(LParent).Show;
42 |
43 | LParent := TWinControl(LParent).Parent;
44 | end;
45 |
46 | try
47 | if(TWinControl(AWinControl).CanFocus)then
48 | TWinControl(AWinControl).SetFocus;
49 | except
50 | end;
51 | end;
52 |
53 | end.
54 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.Types.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components.Types;
2 |
3 | interface
4 |
5 | type
6 | {$SCOPEDENUMS ON}
7 | TLanguageDefault = (ptBR, enUS);
8 | {$SCOPEDENUMS OFF}
9 |
10 | implementation
11 |
12 | end.
13 |
--------------------------------------------------------------------------------
/Src/C4D.Validate.Components.pas:
--------------------------------------------------------------------------------
1 | unit C4D.Validate.Components;
2 |
3 | interface
4 |
5 | uses
6 | System.SysUtils,
7 | System.Classes,
8 | System.RTTI,
9 | Vcl.Forms,
10 | C4D.Validate.Components.Config,
11 | C4D.Validate.Components.Types,
12 | C4D.Validate.Components.FieldDisplay,
13 | C4D.Validate.Components.NotEmpty,
14 | C4D.Validate.Components.Length,
15 | C4D.Validate.Components.MinMaxValue,
16 | C4D.Validate.Components.MinMaxDate;
17 |
18 | type
19 | TLanguageDefault = C4D.Validate.Components.Types.TLanguageDefault;
20 | FieldDisplay = C4D.Validate.Components.FieldDisplay.FieldDisplay;
21 | NotEmpty = C4D.Validate.Components.NotEmpty.NotEmpty;
22 | Length = C4D.Validate.Components.Length.Length;
23 | MinMaxValue = C4D.Validate.Components.MinMaxValue.MinMaxValue;
24 | MinMaxDate = C4D.Validate.Components.MinMaxDate.MinMaxDate;
25 |
26 | TC4DValidateComponents = class
27 | private
28 | public
29 | class function Config: TC4DValidateComponentsConfig;
30 | class procedure Validate(AInstanceClass: TComponentClass; const AForm: TForm);
31 | end;
32 |
33 | implementation
34 |
35 | uses
36 | C4D.Validate.Components.Errors,
37 | C4D.Validate.Components.SetFocus;
38 |
39 | class function TC4DValidateComponents.Config: TC4DValidateComponentsConfig;
40 | begin
41 | Result := TC4DValidateComponentsConfig.GetInstance;
42 | end;
43 |
44 | class procedure TC4DValidateComponents.Validate(AInstanceClass: TComponentClass; const AForm: TForm);
45 | var
46 | LRttiContext: TRttiContext;
47 | LRttiType: TRttiType;
48 | LRttiField: TRttiField;
49 | LCustomAttribute: TCustomAttribute;
50 | begin
51 | TErros.GetInstance.Clear;
52 |
53 | LRttiContext := TRttiContext.Create;
54 | try
55 | LRttiType := LRttiContext.GetType(AInstanceClass);
56 |
57 | for LRttiField in LRttiType.GetFields do
58 | begin
59 | if(LRttiField.Parent <> LRttiType)then
60 | Continue;
61 |
62 | for LCustomAttribute in LRttiField.GetAttributes do
63 | begin
64 | if(LCustomAttribute is NotEmpty)then
65 | NotEmpty(LCustomAttribute).Validar(LRttiField, AForm);
66 |
67 | if(LCustomAttribute is Length)then
68 | Length(LCustomAttribute).Validar(LRttiField, AForm);
69 |
70 | if(LCustomAttribute is MinMaxValue)then
71 | MinMaxValue(LCustomAttribute).Validar(LRttiField, AForm);
72 |
73 | if(LCustomAttribute is MinMaxDate)then
74 | MinMaxDate(LCustomAttribute).Validar(LRttiField, AForm);
75 | end;
76 |
77 | if(TErros.GetInstance.HasErros)and(Self.Config.ShowOneErrorAtATime)then
78 | Break;
79 | end;
80 | finally
81 | LRttiContext.Free;
82 | end;
83 |
84 | if(not TErros.GetInstance.HasErros)then
85 | Exit;
86 |
87 | TRttiSetFocus.SetFocusComponentName(AForm, TErros.GetInstance.GetNameFirstComponent);
88 | raise Exception.Create(TErros.GetInstance.GetMessages);
89 | end;
90 |
91 | end.
92 |
--------------------------------------------------------------------------------
/boss-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "d41d8cd98f00b204e9800998ecf8427e",
3 | "updated": "2023-11-24T11:44:08.9574967-03:00",
4 | "installedModules": {}
5 | }
--------------------------------------------------------------------------------
/boss.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "C4D Validate Components",
3 | "description": "Framework for automatic validation of Delphi forms",
4 | "version": "1.0.0",
5 | "homepage": "https://github.com/Code4Delphi/C4D-Validate-Components",
6 | "mainsrc": "Src/",
7 | "projects": [],
8 | "dependencies": {}
9 | }
--------------------------------------------------------------------------------