-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSystem.pas
More file actions
5101 lines (4525 loc) · 175 KB
/
Copy pathUSystem.pas
File metadata and controls
5101 lines (4525 loc) · 175 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// System Functions
// Date 28.05.22
// CAUTION: Some functions try to access to the HKEY_LOCAL_MACHINE registry key
// resulting in an empty string if the UAC is active on Windows Vista
// and the user has no Administrator privileges!
// ==> Open in read only mode KEY_READ (default is KEY_ALL_ACCESS)
{ TODO : Check NativeInt for 64-bit }
{ TODO : Check all time/date functions if regarding locale time/date delimiters }
{ TODO : Multi processor core to process assignment }
{ TODO : mov ..Form.. procedures to UForm }
{ TODO : all Print.. functions Titel is NOT the document header line !?! }
// Use Delphi/Project/Options/Version/OriginalFileName to check if application
// is already running, value 'MyProg.exe' is shown as 'MyProg.exe is already
// running!' (.exe is required!)
// Use Delphi/Project/Options/Version/Comments to check minimum system version
// like 'MyProg runs on Windows version 5.0 or higher only!' (dot is required!)
// 03.09.09 nk opt show build '.0' as '.Beta' version
// 16.09.09 nk add detection for Windows Server 2003, 2008, 2008 R2, and Windows 7
// 21.09.09 nk add GetMemoryEx for memory > 2GB / get page, virtual, and extended memory
// 30.09.10 nk upd to Delphi XE (2011) Unicode UTF-16LE (Code site 1200)
// 01.07.11 nk opt disable all FPU exceptions to prevent Floating Point Errors
// 17.11.11 nk opt StrToHex and HexToStr functions work on ANSI chars/strings only
// 04.01.12 nk add check if 32-Bit application is running in the WoW64-Subsystem
// 04.01.12 nk add function StrVal to get position of substring in a string list
// 04.02.12 nk add detection for Windows Server 8 and Windows 8 (Version 6.2)
// 23.04.12 nk opt expand buffer lengths from MAXBYTE to MAXBUFF charachers
// 21.01.13 nk add ExitWindows, LockSystem, MinimizeToTray, ShowTitleBar, and BeepTones
// 29.05.14 nk upd to Delphi XE3 (VER240 Version 24)
// 18.12.14 nk add detection of Windows 8.1 and Windows Server 2012 R2
// 20.12.14 nk upd to Delphi XE7 (VER280 Version 28) 32/64-Bit / Indy 10.6
// 24.04.15 nk add support for registry reading under 32 and 64-Bit systems
// 14.08.15 nk add ClockToMins and MinsToClock to convert time models
// 28.11.15 nk add SetWebbrowserMode to set WebBrowser IE compatibility version in registry
// 28.11.15 nk add GetWebbrowserMode to get WebBrowser IE compatibility version from registry
// 28.11.15 nk add detection of Windows 10 and Windows Server 2016
// 28.12.15 nk add SetFormIcon / fix bug in VCL styles regarding LoadIcon()
// 04.01.16 nk opt UNDO all Single, Double, and Extended by Float
// 10.03.16 nk add Is64BitSystem to detect if Windows system is 64-bit or not
// 20.05.16 nk opt for 64-bit version
// 27.03.17 nk fix in SetSystemTime: Regard Daylight Bias
// 25.07.17 nk add GetAllocMemSize as replacement for deprecated AllocMemSize
// 13.05.18 nk fix bug in GetResolution: Returns 0 if no default printer is defined
// 14.12.18 nk fix in SetSystemTime: Regard Daylight Bias ONLY if TIME_ZONE_ID_DAYLIGHT
// 13.07.20 nk fix D10 and beyond it is no longer possible to access strict private or private members in a helper class
// 10.11.20 nk opt GetSystemVers add detection of Windows Server 2019
// 30.11.20 nk add UpdateWinVersion and GetProductInfo to improve GetSystemVers to overcome the limitation of GetVersion(Ex)
// 31.12.20 nk add procedure SortStrings to sort TStrings or TStringList
// 09.10.21 nk add check if another instance of program is already running
unit USystem;
interface
{$WARN SYMBOL_DEPRECATED OFF}
{$WARN SYMBOL_PLATFORM OFF}
uses
Windows, Messages, SysUtils, StrUtils, Classes, Vcl.Forms, StdCtrls, Grids, Math,
Controls, ComCtrls, PsApi, ExtCtrls, Dialogs, Printers, Variants, Graphics,
ExtDlgs, ShlObj, Jpeg, ShellApi, Tlhelp32, WinSpool, TypInfo, UITypes, WinSvc,
Registry, MMSystem, ActiveX, ComObj, SHFolder, UGlobal, URegistry;
const
WM_ACTIVATED = WM_USER + 300;
WM_WINMESSAGE = WM_USER + 301; //V5//11.07.16 nk add
BCM_FIRST = $1600; //button control messages
BCM_SETSHIELD = BCM_FIRST + $000C;
SC_DRAGMOVE = $F012; //03.02.10 nk add
KEY_WOW64_64KEY = $0100; //24.04.15 nk add ff
KEY_WOW64_32KEY = $0200;
TIME_ZONE_ID_UNKNOWN = 0; //14.12.18 nk add ff
TIME_ZONE_ID_STANDARD = 1;
TIME_ZONE_ID_DAYLIGHT = 2;
PROC_INTEL = 0;
PROC_MIPS = 1;
PROC_ALPHA = 2;
PROC_PPC = 3;
PROC_SHX = 4;
PROC_ARM = 5;
PROC_IA64 = 6; //Intel Itanium Processor Family (IPF)
PROC_ALPHA64 = 7;
PROC_MSIL = 8; //Microsoft Intermediate Language
PROC_AMD64 = 9; //x64 (AMD or Intel)
PROC_WOW64 = 10; //WOW64
SOUND_STOP = 0; //Mode of PlaySoundFile
SOUND_SYNC = 1;
SOUND_ASYNC = 2;
SOUND_LOOP = 3;
SM_TABLEPC = 86;
SM_MEDIA = 87;
SM_STARTER = 88;
SM_SERVERR2 = 89;
BETA_BUILD = 0; //03.09.09 nk old=999
WORKSTATION = 1; //16.09.09 nk add
SERVICE_NOP = 8; //21.11.09 nk add
FOOT_SIZE = 9; //17.12.09 nk add
KEY_MASK = 128;
KEY_DELAY = 250; //ms
WAIT_DELAY = 50; //ms
BEEP_DUR = 100; //ms
BEEP_FREQ = 2500; //Hz
BEEP_MAX = 16000; //Hz
SHELL_ERROR = 32; //must be <= 32 (Error code - see GetShellError)
KMULT = 1024.0;
PROCESS_TERM = $0001;
PROC_UNKNOWN = $FFFF;
CMD_MASK = $FFF0;
//BIT_MASK = $FFFFFFFF; //12.09.15 nk mov to UGlobal
AMULT = ' kMGTPE';
FORMERR = '?'; //03.11.08 nk add
UBYTE = 'B';
UBYTES = 'Bytes'; //53//10.11.20 nk add
UHERTZ = 'Hz';
MHERTZ = 'MHz';
MILLISEC = 'ms'; //24.11.09 nk add ff
MICROSEC = 'us';
VERS = 'Vers. ';
BUILD = 'Build ';
BETA_TEXT = 'Beta'; //28.06.09 nk add ff
GROUP_ADMIN = 'Administrator'; //20.09.09 nk add ff
GROUP_USER = 'Standard User';
PRINT_FONT = 'Arial'; //17.12.09 nk add
WIN16 = 'Windows'; //06.10.07 nk add (do NOT change!)
WINNT = 'Windows NT';
WIN2K = 'Windows 2000';
WINXP = 'Windows XP';
WINVS = 'Windows Vista'; //03.05.07 nk add
WIN95 = 'Windows 95';
WIN98 = 'Windows 98';
WINME = 'Windows ME';
WIN32 = 'Windows 32';
WIN3S = 'Windows 3.x (Win32s)';
WINSE = 'Windows 98 SE'; //16.09.09 nk add ff
WIN03 = 'Windows Server 2003';
WIN08 = 'Windows Server 2008';
W08R2 = 'Windows Server 2008 R2';
WIN_7 = 'Windows 7';
WIN_8 = 'Windows 8'; //04.02.12 nk add ff
WIN_8S = 'Windows Server 8';
WIN12 = 'Windows Server 2012'; //13.09.13 nk add
WIN_81 = 'Windows 8.1'; //20.12.14 nk add ff
WIN12R2 = 'Windows Server 2012 R2';
WIN_10 = 'Windows 10'; //28.11.15 nk add ff
WINS16 = 'Windows Server 2016';
WINS19 = 'Windows Server 2019'; //53//10.11.20 nk add
WINSYS32 = ' (32-bit)'; //V5//18.03.16 nk add ff
WINSYS64 = ' (64-bit)';
//29.05.14 nk add ff - Application's Target system
IMAGE_FILE_MACHINE_I386 = $014c; // Intel x86
IMAGE_FILE_MACHINE_IA64 = $0200; // Intel Itanium Processor Family (IPF)
IMAGE_FILE_MACHINE_AMD64 = $8664; // x64 (AMD64 or EM64T)
IMAGE_FILE_MACHINE_R3000_BE = $160; // MIPS big-endian
IMAGE_FILE_MACHINE_R3000 = $162; // MIPS little-endian, 0x160 big-endian
IMAGE_FILE_MACHINE_R4000 = $166; // MIPS little-endian
IMAGE_FILE_MACHINE_R10000 = $168; // MIPS little-endian
IMAGE_FILE_MACHINE_ALPHA = $184; // Alpha_AXP
IMAGE_FILE_MACHINE_POWERPC = $1F0; // IBM PowerPC Little-Endian
SHELL_EXEC = 'open';
SHELL_RUNAS = 'runas'; //27.11.09 nk add
SHELL_WHERE = 'where'; //15.12.09 nk add
SHELL_NOTEPAD = 'notepad'; //16.01.10 nk add
SHELL_TASKMAN = 'taskmgr'; //21.01.13 nk add
SHELL_SYSCONF = 'msconfig'; //21.01.13 nk add
SHELL_REGSVR = 'regsvr32'; //12.04.11 nk add ff
SHELL_DLLREG = 'DllRegisterServer';
SHELL_TRAY = 'Shell_TrayWnd'; //06.10.07 nk add
SHELL_CMD = 'COMSPEC'; //12.09.08 nk add - dos console (cmd)
SHELL_SWITCH = 'SwitchToThisWindow'; //30.11.10 nk add
TRAY_NOTIFY = 'TrayNotifyWnd'; //16.12.07 nk add
TRAY_PAGER = 'SysPager'; //16.02.08 nk add ff
TRAY_TOOLBAR = 'ToolbarWindow32';
SHUTDOWN_NAME = 'SeShutdownPrivilege'; //20.01.13 nk add ff
LOCK_SYSTEM = 'LockWorkStation';
KEY_DEV = 'device';
FILE_PROPERTY = 'properties'; //07.12.09 nk old=FILE_INFO
CLASS_BUTTON = 'Button'; //31.12.07 nk add
DESKTOP_APP = 'Program Manager';
DELPHI_APP = 'TAppBuilder';
THEME_ISACT = 'IsThemeActive'; //14.04.08 nk old=ThemeAct
PROC_IS64 = 'IsWow64Process'; //04.01.12 nk add
ADO_CONNECT = 'adodb.connection'; //30.11.10 nk add
API_KERNEL = 'kernel32.dll'; //04.01.12 nk add
API_UXTHEME = 'uxtheme.dll'; //25.11.10 nk old=THEME_LIB / 14.04.08 nk old=ThemeLib
API_NETAPI = 'netapi32.dll'; //25.11.10 nk mov from UInternet as INET_API_
API_SHDOCVW = 'shdocvw.dll';
API_SHELL = 'shell32.dll';
API_USER = 'user32.dll'; //20.01.13 nk add
API_IPHLP = 'iphlpapi.dll';
API_MAPI = 'MAPI32.dll';
API_RUNDLL = 'rundll32.exe';
API_MSINFO = 'msinfo32.exe'; //30.05.11 nk add
API_NT = 'ntdll.dll'; //25.11.10 nk mov from UDiag
API_MSJET = 'msjet40.dll';
API_MSSQL = 'sqlservr.exe';
API_WMP = 'wmp.dll'; //25.11.10 nk add
API_DXDIAG = 'dxdiag.exe'; //11.10.11 nk add
REG_SMW_KEY = '\Software\Microsoft\Windows NT\CurrentVersion'; //20.09.09 nk add ff
REG_CDROM_KEY = '\Software\Microsoft\Windows\CurrentVersion\Explorer\CD Burning';
REG_UAC_KEY = '\Software\Microsoft\Windows\CurrentVersion\Policies\System'; //30.11.10 nk add
REG_ERROR_KEY = '\Software\Microsoft\Windows\Windows Error Reporting\'; //13.05.11 nk add
REG_IEM_KEY = '\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION'; //28.11.15 nk add
REG_DX_KEY = '\Software\Microsoft\DirectX';
REG_HWD_KEY = '\Hardware\Description\System';
REG_DEV_KEY = '\Hardware\Devicemap';
REG_CLASS_KEY = '\System\CurrentControlSet\Control\Class'; //30.11.10 nk add
REG_KBD_KEY = '\System\CurrentControlSet\Control\Keyboard Layouts\'; //29.11.10 nk add
REG_DESK_KEY = '\Control Panel\Desktop'; //25.11.10 nk add
REG_INT_KEY = '\Control Panel\International'; //01.10.10 nk add
REG_CPU_NAME = 'ProcessorNameString';
REG_CPU_PID = 'Identifier';
REG_CPU_VID = 'VendorIdentifier';
REG_BIOS = '\BIOS'; //20.09.09 nk add ff
REG_VERSION = 'Version';
REG_NAME = 'Name'; //30.11.10 nk add ff
REG_CLASS = 'Class';
REG_SUBCLASS = '0000';
REG_MOUSE = 'Mouse';
REG_PROVIDER = 'ProviderName';
REG_DRDESC = 'DriverDesc';
REG_INSTVERS = 'InstalledVersion'; //03.01.09 nk add
REG_UAC = 'EnableLUA'; //30.11.10 nk add
REG_SHOWUI = 'DontShowUI'; //13.05.11 nk add ff
REG_DISABLE = 'Disabled';
REG_CDROM = 'CD Recorder Drive';
REG_BIOS_MANU = 'BIOSVendor'; //28.11.10 nk opt ff
REG_BIOS_VERS = 'BIOSVersion';
REG_BIOS_RDAT = 'BIOSReleaseDate';
REG_BIOS_DATE = 'SystemBiosDate';
REG_BORD_MANU = 'BaseBoardManufacturer';
REG_BORD_NAME = 'BaseBoardProduct';
REG_COMP_MANU = 'SystemManufacturer';
REG_COMP_NAME = 'SystemProductName';
REG_COMP_TYPE = 'Identifier';
REG_VID_VERS = 'VideoBiosVersion';
REG_VID_DATE = 'VideoBiosDate';
REG_ORGANISAT = 'RegisteredOrganization'; //19.09.09 nk add
REG_OWNER = 'RegisteredOwner'; //23.11.10 nk add ff
REG_PRODNAME = 'ProductName';
REG_PRODCODE = 'ProductId';
REG_EDITION = 'EditionID';
REG_CURVERS = 'CurrentVersion';
REG_CURBUILD = 'CurrentBuild';
REG_CSDBUILD = 'CSDBuildNumber';
REG_CSDVERS = 'CSDVersion';
REG_LAYOUT = 'Layout Text'; //29.11.10 nk add
REG_LOCALE = 'LocaleName'; //01.10.10 nk add
REG_SCOUNTRY = 'sCountry'; //25.02.16 nk old=REG_COUNTRY -> conflict with URegistry
REG_SS_ACTIVE = 'ScreenSaveActive'; //25.11.10 nk add ff
REG_SS_DELAY = 'ScreenSaveTimeOut';
REG_DOS_DEVS = '\DosDevices\';
REG_CPU_SPEED = '~MHz';
REG_KEY_ICON = '\DefaultIcon'; //04.03.08 nk mov ff from RegisterFileType
REG_KEY_OPEN = '\Shell\Open\Command';
REG_KEY_ATTR = ' "%1"';
REG_PAR_ICON = ',0';
REG_COM_KEY = REG_DEV_KEY + '\Serialcomm';
REG_LPT_KEY = REG_DEV_KEY + '\Parallel Ports';
REG_CPU_KEY = REG_HWD_KEY + '\CentralProcessor\0';
DOS_PIPE = ' > '; //15.12.09 nk add
VER_SLASH = '\\'; //14.04.08 nk mov ff
VER_VARFILE = VER_SLASH + 'VarFileInfo\\Translation';
VER_STRING = VER_SLASH + 'StringFileInfo' + VER_SLASH;
//20.09.09 nk add ff
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = (Value: (0, 0, 0, 0, 0, 5));
SECURITY_BUILTIN_DOMAIN_RID = $00000020;
DOMAIN_ALIAS_RID_ADMINS = $00000220;
FORM_VERS = '%d.%d'; //14.04.08 nk mov ff
FORM_SBUILD = '%d.%d.%d';
FORM_SSHORT = '%s (%d.%d)';
FORM_SLONG = '%s (%d.%d.%d)';
FORM_SPACK = '%s (%s)';
FORM_VFULL = '%d.%d.%d %s Build %d'; //23.11.10 nk add
FORM_PSHORT = '%d.%d.%d';
FORM_PLONG = '%d.%d.%d.%s'; //28.06.09 nk old=%d';
FORM_PNAME = '%s%d.%d';
FORM_PPACK = '%s%d';
FORM_CHECK = '%s.%s'; //16.04.08 nk add
FORM_EXECUTE = '"%s" "%s"'; //30.11.10 nk add
FORM_SCREEN = '%d x %d x %d (%d %s)'; //06.10.07 nk add
FORM_SCREENS = '%d x %d x %d'; //24.08.13 nk add
FORM_HEADER = ' %s Vers. %s - %s'; //18.04.08 nk add ff
FORM_AGENT = ' %s Vers. %s'; //12.12.08 nk add
FORM_TIMEZONE = '%s (UTC%s%d)'; //like 'Central Time (UTC-8)'
FORM_FOOTER = 'Page %d of %d'; //30.11.10 nk add ff
FORM_MEMORY = 'Total: %s / Free: %s';
FORM_UPTIME = '%d Days, %d Hours, %d Minutes, %d Seconds';
FORM_FORMSET = 'Decimal Separator is "%s", Thousand Separator is "%s"';
FORM_RUNNING = 'An instance of %s is already running!';
FORM_ABORTJOB = 'Print job is being aborted!';
//14.04.08 nk mov / old=InfoStr - must corresponde with TAppInfo
InfoStrings: array[1..10] of string = (
'CompanyName',
'FileDescription',
'FileVersion',
'InternalName',
'LegalCopyright',
'LegalTradeMarks',
'OriginalFileName',
'ProductName',
'ProductVersion',
'Comments');
//21.11.09 nk opt / add SERVICE_NOP / old=SERVICE_PAUSED
InfoService: array[NERR_SUCCESS..SERVICE_NOP] of string = (
'Service is not installed',
'Service is stopped',
'Service is starting...',
'Service is stopping...',
'Service is running',
'Service is continuing...',
'Service is pausing...',
'Service is paused',
'Unknown service status!');
type //03.09.09 nk mov up
NET_API_STATUS = DWORD; //53//30.11.20 nk add
//21.09.09 nk add msPTotal..msXFree / opt new ordering
TMemSize = (msTotal, msFree, msUsed, msPTotal, msPFree, msVTotal, msVFree,
msXFree, msPLoad, msBlock, msHeap, msProc, msSpace, msUncom,
msCom, msAlloc, msTfree, msSfree, msBfree, msUnuse, msOver,
msLoad, msError);
TSizeFormat = (sfByte, sfKilo, sfMega, sfGiga, sfTera, sfPeta, sfExa, sfAuto);
TVersType = (vtVerMaj, vtVerMin, vtRelMaj, vtRelMin, vtBuild, vtVers,
vtPack, vtName, vtShort, vtLong, vtDesc, vtFull, vtSP); //13.09.13 nk add vtSP / 23.11.10 nk add vtFull / 16.09.09 nk add vtDesc
TFormComm = (fcClose, fcMinimize, fcMaximize, fcRestore);
TDevType = (dtScreen, dtPrinter);
TIEMode = (iemIE7, iemIE8, iemIE9, iemIE10, iemIE11); //28.11.15 nk add - WebBrowser compatibility versions
TAppInfo = (piCompanyName, piFileDescription, piFileVersion, piInternalName,
piLegalCopyright, piLegalTradeMarks, piOriginalFileName,
piProductName, piProductVersion, piComments, piProjectName,
piFileName, piProgName, piProgPath);
TWmMoving = record
Msg : Cardinal;
fwSide: Cardinal;
lpRect: PRect;
Result: Integer;
end;
type TOsVersionInfoEx = packed record //16.09.09 nk add
dwOSVersionInfoSize: DWORD;
dwMajorVersion : DWORD;
dwMinorVersion : DWORD;
dwBuildNumber : DWORD;
dwPlatformId : DWORD;
szCSDVersion : array [0..127] of WideChar;
wServicePackMajor : Word;
wServicePackMinor : Word;
wSuiteMask : Word;
wProductType : Byte;
wReserved : Byte;
end;
type TMemoryStatusEx = packed record //21.09.09 nk add
dwLength: DWORD;
dwMemoryLoad: DWORD;
ullTotalPhys: Int64;
ullAvailPhys: Int64;
ullTotalPageFile: Int64;
ullAvailPageFile: Int64;
ullTotalVirtual: Int64;
ullAvailVirtual: Int64;
ullAvailExtendedVirtual: Int64;
end;
var
SIDEBORDER: Integer = 6; //window metrics will be
TOPBORDER: Integer = 25; //corrected by GetWindowMetric
CAPTIONHEIGHT: Integer = 28; //04.02.16 nk add
SCROLLBARWIDTH: Integer = 22; //on initialization
BORDERCORR: Integer = 0; //25.10.07 nk add ff
TABLECORR: Integer = 0; //18.07.09 nk add
SCREENWIDTH: Integer = 800; //screen width
SCREENHEIGHT: Integer = 600; //and height [pixel]
SCREENCENTER: Integer = 400; //26.03.08 nk add ff
SCREENMIDDLE: Integer = 300;
FORMLEFT: Integer = 100;
FORMTOP: Integer = 100;
VIEWWIDTH: Integer = 720; //V5//21.01.16 nk add ff
VIEWHEIGHT: Integer = 480;
VIEWTOP: Integer = 20;
FORMWIDTH: Integer = 800; //V5//09.01.16 nk opt ff
FORMHEIGHT: Integer = 600;
PrinterLeftMargin: Integer; //printer margins [mm]
PrinterTopMargin: Integer;
PrinterHeaderSize: Integer;
PrinterFooterSize: Integer;
PrinterRowHeight: Integer;
PrinterFontHeight: Integer;
PaperA4Width: Integer; //26.11.15 nk add - get A4 portrait size [pixels]
PaperA4Height: Integer;
ScreenDelay: Integer; //25.11.10 nk add [min] (0=Off)
ExecCode: Cardinal; //20.02.08 nk add
TimerRes: Int64;
MutexHandle: THandle;
//set this infos on program initialization
SysError: string; //04.03.08 nk add
SysLogFile: string; //27.02.17 nk add
StringPart: string;
ComputerUser: string;
TimeFormatShort: string; //03.11.08 nk add ff
TimeFormatLong: string;
DateFormatShort: string;
DateFormatLong: string; //20.11.15 nk add
//fill in this infos in Delphi/Project/Options/Version
CompanyName: string;
FileDescription: string;
FileVersion: string;
InternalName: string;
LegalCopyright: string;
LegalTradeMarks: string;
OriginalFileName: string; //use original file name to check if already running
ProductName: string;
ProductVersion: string;
Comments: string; //use comments to check minimum system version
//this infos will be set on initialization
FontScale: Single; //02.04.08 nk add (1.0 = 96dpi / 1.25 = 120dpi)
ProjectName: string; //Personal Integrated Dive Instrument
FileName: string; //Pidi.exe
ProgName: string; //Pidi
ProgPath: string; //C:\Program Files\Pidi\
ProgBuild: string; //24.03.08 nk add like '715'
ProductHeader: string; //Mail Reader Vers. 1.8 - Copyright by seanus systems
ProductAgent: string; //Mail Sender Vers. 1.6 by seanus systems
ProductTitle: string; //01.04.16 nk add
OSVI: TOSVersionInfo; //53//30.11.20 nk add ff
OSVIA: TOsVersionInfoA;
OSVIX: TOSVersionInfoEx;
function IsEven(Val: Byte): Boolean; //V5//06.08.15 nk add
function Iff(const Condition: Boolean; const TruePart, FalsePart: Variant): Variant; //25.11.10 nk add
function Digits(const Val: Cardinal): Byte; //30.07.09 nk add
function NotEmpty(Val: string): Boolean; //30.10.09 nk add
function GetBit(const Opr: Cardinal; const Bit: Byte): Boolean;
function SetBit(const Opr: Cardinal; const Bit: Byte; Val: Boolean): Cardinal;
function ToggleBit(const Opr: Cardinal; const Bit: Byte): Cardinal;
function Toggle(Bit: Integer): Integer; //09.12.07 nk add
function StrIsNumeric(Input: string): Boolean; //22.11.13 nk add
function StrContain(Str1, Str2: string): Boolean; //05.10.13 nl add
function StrEqual(Str1, Str2: string; Len: Integer = 0): Boolean; //12.10.12 nk old=Word / 27.12.10 nk add
function StrSplit(Input: string; Del: Char; Pos: Integer): string;
function StrCut(Input: string; var Output: string; Del: Char = cCOMMA): Boolean; //15.03.10 nk add Del
function StrVal(Instr, Substr: string; Del: Char = cCOMMA): Integer; //04.01.12 nk add
function StrStrip(Input: string; StripChars: TCharSet): string; //28.07.10 nk add
function StrTrim(Input: string): string; //22.02.13 nk add
function StrCount(Input: string; Search: Char): Integer;
function StrNum(Input: string): string; //16.02.10 nk add
function CutNum(Input: string): string; //V5//07.10.15 nk add
function StrVers(Version: string; StartNum: Integer = 1): Single; //28.09.19 nk add StartNum
function StrToIntRange(Input: string; Lmin, Lmax: Integer): Integer; //V5//18.11.16 nk add
function StrToClock(Seconds: Integer): TDateTime; //20.12.14 nk add
function StrToVers(Version: string): Single; //18.11.08 nk opt
function StrToHex(Text: AnsiString): AnsiString; //17.11.11 nk old=string xe
function HexToStr(Hex: AnsiString): AnsiString; //17.11.11 nk old=string xe
function StringIndex(Input: string; List: array of string): Integer; //06.10.07 nk add
//function ProperAnsi(Input: string): string; //obsolete / 05.06.12 nk add
function ProperString(Input: string): string; //11.07.12 nk add
function ProperCase(Input: string; FirstOnly: Boolean = False): string; //25.08.08 nk add FirstOnly
function CamelCase(Input: string): string;
function TrimEx(Input: string): string; //06.11.11 nk add
function TrimAll(Input: string; ValidChars: TCharSet = EMPTY_SET): string; //18.07.07 nk add
function CreateHint(HeadText: string; TailText: string = cEMPTY): string;
function WinToDos(Input: string): string; //18.07.07 nk add
function DosToWin(Input: string): string; //18.07.07 nk add
function CharToPhon(Input: string): string; //18.07.07 nk add
function Limit(Val, Min, Max: Integer): Integer; //11.02.08 nk add
function RoundUp(Val: Double): Integer; //30.05.09 nk add
function RoundIt(Val: Double; Lim: Double = 0.5): Double; //18.11.10 nk add
function IntToByte(Int: Integer): Byte;
function FloatToByte(Float: Single): Byte; //24.03.09 nk add //19.09.09 nk add Gap
function FormatByte(Bytes: Int64; Format: TSizeFormat; Digit: Byte; Gap: string = cSPACE): string;
function DeFormatByte(Bytes: string): Int64;
function IsAlive(ProgName: string; UseClass: Boolean = False): Boolean; //10.04.08 nk add
function IsAdmin: Boolean; //20.09.09 nk upd
function IsUACEnabled: Boolean; //30.11.10 nk add
function Is32AppOn64Bit: Boolean; //04.01.12 nk add
function Is64BitSystem: Boolean; //10.03.16 nk add
function GetTargetSystem(var AppName: string): Boolean; //29.05.14 nk add
function GetDelphi: Boolean;
function GetBurner: Boolean; //19.09.09 nk add
function GetFont(out FontSize: Integer): Boolean;
function GetFontSize: string; //19.09.09 nk add
function GetFontScale: Single; //02.04.08 nk add
function GetScreenFont(FontName: string): Boolean; //22.09.09 nk add ff
function GetPrinterFont(FontName: string): Boolean;
function GetFontHeight(FontType: TFont): Integer; //10.06.11 nk opt / 24.07.07 nk add
function GetFontWidth(FontType: TFont): Integer; //10.06.11 nk add
function GetMin(x, y: Extended): Extended;
function GetMax(x, y: Extended): Extended;
function GetMouse: string; //30.11.10 nk add
function GetMouseButtons: Integer;
function GetMouseWheel: Integer;
function GetPorts(Ports, Devices: TStrings): Integer;
function GetProcessorSpeed: Int64;
function GetProcessorName: string;
function GetProcessorClock: string;
function GetProcessorVers(VersType: TVersType): string;
function GetMemory(SizeType: TMemSize): Int64;
function GetMemoryEx(SizeType: TMemSize): Int64; //05.09.13 nk opt (was missed!?!)
function GetPhysicalMemory: string; //19.09.09 nk add
function GetVirtualMemory: string; //21.09.09 nk add
function GetAllocMemSize: Cardinal; //28.05.22 nk old=Integer / 25.07.17 nk add
function GetProcessList(ProcList: TStrings; Filter: string = cEMPTY): Integer; //14.04.08 nk add
function GetProcessMemory(InPercent: Boolean = False; ProcHandle: Cardinal = 0): Int64; //27.11.15 nk add InPercent
function GetProcessID(ProgName: string): Cardinal; //04.11.07 nk add
function GetProcessPrio(var ProgName: string): Integer; //27.05.10 nk add
function GetProcessHandle(ProgName: string; UseClass: Boolean = False): HWND; //27.05.10 nk add
function GetTimer: Int64;
function GetIdleTime: Cardinal; //02.06.11 nk add
function GetUTCTime: TDateTime; //14.06.11 nk add
function GetUpTime: string; //19.09.09 nk add
function GetBootTime: string; //22.09.09 nk add
function GetServiceStatus(Machine, Service: PChar): DWORD; //03.09.09 nk add
function GetPowerStatus(out Remain: Integer): Boolean;
function GetDirectXVers: string; //20.09.09 nk add
function GetADOVers: string; //20.09.09 nk add
function GetProgVers(VersType: TVersType; ProgName: string = cEMPTY): string; //22.01.08 nk add ProgName
function GetSystemVers(VersType: TVersType): string; //16.09.09 nk add improved version
function GetAppInfo(AppInfo: TAppInfo): string;
function GetEnvVar(EnvName: string): string;
function GetWindowMetric(Metric: Byte = 0): Integer; //25.10.07 nk add
function GetTopWindow(Win: HWND): Boolean; //27.03.08 nk add
function GetFocusWindow: Cardinal; //10.04.08 nk add
function GetXpStyle: Boolean;
function GetSoundCard: Boolean; //13.08.09 nk add
function GetBiosVers(Video: Boolean = False): string; //20.09.09 nk add Video
function GetBiosDate(Video: Boolean = False): string; //20.09.09 nk add Video
function GetSystemLang: string;
function GetKeyboardLang(Code: string = cEMPTY): string; //29.11.10 nk add Code
function GetLocalSettings(Default: Boolean): string; //19.09.09 nk add
function GetCompName: string;
function GetCompUser: string;
function GetOrganisation: string; //19.09.09 nk add
function GetSerialNo(UseWinDrive: Boolean = False): string; //09.11.09 nk add UseWinDrive
function GetDefPrinter: string; //27.05.10 nk add
function GetDefaultPrinter: string;
function GetProductData(DataTyp: Byte): string; //20.09.09 nk add
function GetWindowsData(DataTyp: Byte): string; //23.11.10 nk add
function GetClock(Seconds: Integer; DoLimit: Boolean = False): string; //11.10.09 nk add DoLimit
function ClockToMins(Clock: string): Word; //V5//14.08.15 nk add
function MinsToClock(Minutes: Word): string; //V5//14.08.15 nk add
function GetTimeZone: string; //19.09.09 nk add
function GetValidTime(TimeValue, TimeFormat: string; var Seconds: Integer; DoLimit: Boolean = False): string; //11.10.09 nk add DoLimit
function GetPrinterFormats(FormatList: TStrings): Integer;
function GetScreen(out Width, Height, Freq, Bits: Cardinal): string;
function GetScreenSaver: Integer; //25.11.10 nk add
function GetResolution(Device: TDevType): Integer;
function GetShellError(ErrCode: Integer): string; //17.04.07 nk add
function GetLastErrorText: string; //08.12.09 nk add
function GetUserAccount: string; //20.09.09 nk add
function GetUserPrivileges(UserList: TStringList): Integer; //18.09.09 nk add
function GetHtmlChar(Code: string): Char; //21.10.10 nk mov from UInternet
function GetWebbrowserMode(AppName: string = cEMPTY): Integer; //28.11.15 nk add
function PreventFormMove(Msg: TwmSysCommand): Boolean;
function PreventFormSize(Msg: TwmSysCommand): Boolean;
function PreventFormChange(Msg: TwmSysCommand): Boolean;
function CheckMinSystem(MinVers: string): Boolean; //16.04.08 nk add
function LockSystem: Boolean; //20.01.13 nk add
function KillTask(TaskName: string): Integer;
function ExitWindows(RebootParam: Longword): Boolean; //20.01.13 nk add
function MinimizeToTray(Handle: HWND): Boolean; //20.01.13 nk add
function ExecuteAndWait(FileName: string; Params: PChar; PathName: string = cEMPTY): Boolean; //06.09.11 nk old=procedure
function ExecuteEmbedded(FileName, ProgCaption: string; Params: PChar; ProgParent: THandle; PathName: string = cEMPTY): THandle; //17.03.15 nk add
function DoStartService(Machine, Service: string): Boolean; //03.09.09 nk add
function DoStopService(Machine, Service: string): Boolean; //04.09.09 nk add
function MimeToHtml(Code: string): string; //21.10.10 nk mov from UInternet
function SetScreen(Width, Height, Freq: Cardinal): Boolean;
function SetFormIcon(FormHandle: HWND; IconName: string): Integer; //V5//28.12.15 nk add
function SetSystemTime(SysTime: TDateTime): Boolean; //V5//05.01.17 nk add
function MessageSend(ProgName, Text: string; UseClass: Boolean = False): Boolean; //V5//11.07.16 nk add
function UpdateWinVersion: string; //53//30.11.20 nk add
procedure SetBackGround(BitMap: string);
procedure SetTopWindow(Win: HWND; Restore: Bool); stdcall; //10.04.08 nk add
procedure SetDefaultPrinter(PrinterName: string); //06.07.08 nk add
procedure SetLocalSettings(Dsep, Tsep: Char); //24.09.09 nk add
procedure SetAdminShield(Control: TWinControl; Requiered: Boolean); //27.11.09 nk add
procedure SetScreenSaver(Delay: Integer); //25.11.10 nk add
procedure SetErrDialog(Mode: Boolean); //13.05.11 nk add
procedure SetKeyboardState(Key: Byte; State: Boolean);
procedure SetWebbrowserMode(Mode: TIEMode; AppName: string = cEMPTY); //28.11.15 nk add
procedure Delay(MilliSeconds: Longword);
procedure DelayMicro(MicroSeconds: Int64);
procedure Beep(Freq: Integer = BEEP_FREQ; Dur: Integer = BEEP_DUR);
procedure BeepTones; //21.01.13 nk add
procedure ShowScreen(Mode: Boolean);
procedure ShowTaskBar(Mode: Boolean);
procedure ShowTitleBar(Form: TForm; Mode: Boolean); //21.01.13 nk add
procedure ShowStartButton(Mode: Boolean);
procedure ShowDesktopIcons(Mode: Boolean);
procedure SwapMouseButtons(Mode: Boolean);
procedure ClipMouseCursor(Area: TRect);
procedure EnableCloseButton(Window: TForm); //19.04.08 nk add
procedure DisableCloseButton(Window: TForm); //19.04.08 nk add
procedure HideCloseButton(Window: TForm); //19.04.08 nk old=Disable...
procedure HideMinButton(Window: TForm); //19.04.08 nk old=Disable...
procedure HideMaxButton(Window: TForm); //19.04.08 nk old=Disable...
procedure ShowFormContents(Mode: Boolean);
procedure LimitFormMove(Area: TRect; Msg: TwmMoving);
procedure RestartApplication(Param: string = cEMPTY); //V5//08.02.17 nk add Param
procedure PerformApplication(ProgName: string; Comm: TFormComm; UseClass: Boolean = False); //UseClass 22.01.13 nk add hhh / 20.02.08 nk add ff PathName
procedure ExecuteDocument(FileName: string; WaitForClose: Boolean = False); //13.01.09 nk add
procedure ExecuteProgram(FileName: string; Params: PChar; PathName: string = cEMPTY);
procedure ExecuteAsAdmin(FileName, Params: string; PathName: string = cEMPTY); //27.11.09 nk add
procedure ExecuteDosComm(DosComm: string; Hidden: Boolean); //12.09.08 nk add
procedure PressKey(const CtrlKey: array of Byte);
procedure SetWaveVolume(Left, Right: Word);
procedure PlaySoundFile(SoundFile: string; Mode: Byte = SOUND_ASYNC);
procedure PlaySoundSystem(SystemSound: Integer); //13.08.09 nk add
procedure MakeSound(Freq, Dur, Vol: Integer);
procedure PrintText(Header: string; Text: TRichEdit);
procedure PrintGrid(Header: string; Grid: TStringGrid);
procedure PrintImage(LeftFooter, RightFooter: string; Image: TImage; Zoom: Integer); //17.12.09 nk opt ff
procedure CloneObject(Source, Target: TObject);
procedure RegisterLibrary(LibName: string); //12.04.11 nk add
procedure RegisterFileType(Prefix, AppFile, AppName: string);
procedure WaitOnKey(Key: Integer = NONE); //03.03.15 nk opt
procedure ClearKeyboardBuffer;
procedure ClearMouseBuffer;
procedure RemoveZombies; //16.12.07 nk add
procedure TrimAppMemorySize; //02.06.11 nk add
procedure SortStrings(Strings: TStrings; Duplicates: TDuplicates = dupAccept); //31.12.20 nk add
implementation
function GlobalMemoryStatusEx(var lpBuffer: TMemoryStatusEx): BOOL; stdcall;
external API_KERNEL; //21.09.09 nk add
function GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion: DWORD; var pdwReturnedProductType: DWORD): BOOL; stdcall;
external API_KERNEL; //53//30.11.20 nk add
function NetServerGetInfo(Servername: PWideChar; Level: DWORD; var Bufptr: Pointer): NET_API_STATUS; stdcall;
external API_NETAPI; //53//30.11.20 nk add
function NetApiBufferFree(Bufptr: Pointer): NET_API_STATUS; stdcall;
external API_NETAPI; //53//30.11.20 nk add
procedure SetTopWindow(Win: HWND; Restore: Bool); stdcall;
external user32 Name SHELL_SWITCH;
//use like 'SetTopWindow(FindWindow('notepad', nil), True);
//NOTE: Better use SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
function Iff(const Condition: Boolean; const TruePart, FalsePart: Variant): Variant;
begin //25.11.10 nk add - Replacement for the C ternary conditional operator ? (JEDI JclSysUtils)
if Condition then //If Condition=True then Result=TruePart else Result=FalsePart
Result := TruePart
else
Result := FalsePart;
end;
function IsEven(Val: Byte): Boolean;
begin //V5//06.08.15 nk add - return True if Val is even and False if odd
Result := Val mod 2 = 0;
end;
function GetBit(const Opr: Cardinal; const Bit: Byte): Boolean;
begin //Bit counts from 0 (LSB) to 31 (MSB) / return True if Bit is set in Opr
Result := (Opr and (1 shl Bit)) <> 0;
end;
function SetBit(const Opr: Cardinal; const Bit: Byte; Val: Boolean): Cardinal;
begin //Bit counts from 0 (LSB) to 31 (MSB)
if Val then
Result := Opr or (1 shl Bit)
else
Result := Opr and ((1 shl Bit) xor BIT_MASK);
end;
function ToggleBit(const Opr: Cardinal; const Bit: Byte): Cardinal;
begin //Bit counts from 0 (LSB) to 31 (MSB)
Result := Opr xor (1 shl Bit);
end;
function Toggle(Bit: Integer): Integer;
begin //toggle bit from 0 -> 1 -> 0..
Result := abs(Bit - 1);
end;
function Digits(const Val: Cardinal): Byte;
begin //12.12.09 nk opt - return number of digits of Val
if Val <= 0 then //e.g. Val=1249 => Digits=4
Result := 1
else
Result := Trunc(Log10(Val)) + 1;
end;
function NotEmpty(Val: string): Boolean;
begin //06.11.11 nk opt - Return True if Val is empty or has only space(s)
Result := (TrimEx(Val) <> cEMPTY); //06.11.11 nk old=Trim
end;
function WinToDos(Input: string): string;
begin //xe//convert Win (ANSI) character codes to DOS
Result := Input;
if Input = cEMPTY then Exit; //12.09.08 nk opt
UniqueString(Result);
CharToOem(PChar(Result), PAnsiChar(AnsiString(Result))); //xe//
end;
function DosToWin(Input: string): string;
begin //xe//convert DOS character codes to Win (ANSI)
Result := Input;
if Input = cEMPTY then Exit; //12.09.08 nk opt
UniqueString(Result);
OemToChar(PAnsiChar(AnsiString(Result)), PChar(Result)); //xe//
end;
function CharToPhon(Input: string): string;
var //xe//convert special character codes to homonymic phonemes
i: Integer;
ch: string;
begin
Result := cEMPTY;
for i := 1 to Length(Input) do begin
ch := cEMPTY; //ignore control codes
if (Ord(Input[i]) >= ASCII_SPACE) and (Ord(Input[i]) < ASCII_LAST) then ch := Input[i];
if CharInSet(Input[i], ['à','á','â','ã','å']) then ch := 'a';
if CharInSet(Input[i], ['À','Á','Â','Ã','Å']) then ch := 'A';
if CharInSet(Input[i], ['ò','ó','ô','õ','ø']) then ch := 'o';
if CharInSet(Input[i], ['Ò','Ó','Ô','Õ','Ø']) then ch := 'O';
if CharInSet(Input[i], ['ù','ú','û','µ']) then ch := 'u';
if CharInSet(Input[i], ['Ù','Ú','Û']) then ch := 'U';
if CharInSet(Input[i], ['è','é','ê','ë']) then ch := 'e';
if CharInSet(Input[i], ['È','É','Ê','Ë','']) then ch := 'E';
if CharInSet(Input[i], ['ì','í','î','ï']) then ch := 'i';
if CharInSet(Input[i], ['Ì','Í','Î','Ï']) then ch := 'I';
if CharInSet(Input[i], ['ý','ÿ']) then ch := 'y';
if CharInSet(Input[i], ['Ý','','¥']) then ch := 'Y';
if CharInSet(Input[i], ['ä','æ']) then ch := 'ae';
if CharInSet(Input[i], ['Ä','Æ']) then ch := 'Ae';
if CharInSet(Input[i], ['ö','']) then ch := 'oe';
if CharInSet(Input[i], ['Ö','']) then ch := 'Oe';
if CharInSet(Input[i], ['ç','¢']) then ch := 'c';
if CharInSet(Input[i], ['Ç','©']) then ch := 'C';
if (Input[i] = 'ü') then ch := 'ue';
if (Input[i] = 'Ü') then ch := 'Ue';
if (Input[i] = 'Ð') then ch := 'D';
if (Input[i] = 'ñ') then ch := 'n';
if (Input[i] = 'Ñ') then ch := 'N';
if (Input[i] = '£') then ch := 'L';
if (Input[i] = '') then ch := 's';
if (Input[i] = '') then ch := 'S';
if (Input[i] = '®') then ch := 'R';
if (Input[i] = '') then ch := 'z';
if (Input[i] = '') then ch := 'Z';
if (Input[i] = 'ß') then ch := 'ss';
Result := Result + ch;
end;
end;
function IntToByte(Int: Integer): Byte;
begin //convert an Integer to a Byte (limited to 0..255)
if Int > MAXBYTE then
Result := MAXBYTE
else if Int < 0 then
Result := CLEAR
else
Result := Int;
end;
function FloatToByte(Float: Single): Byte;
begin //24.03.09 nk add - convert a Float to a Byte (rounded and limited to 0..255)
Result := IntToByte(Round(Float));
end;
function Limit(Val, Min, Max: Integer): Integer;
begin //limit Val between (inclusive) Min and Max
if Val < Min then Val := Min;
if Val > Max then Val := Max;
Result := Val;
end;
function RoundUp(Val: Double): Integer;
var //round real value Val up to the next integer value
fix: Integer; //e.g. 12.35 => 13, but 12.0 => 12
begin
fix := Trunc(Val); //integer part
if Frac(Val) > NADA then //fractional part
Result := fix + 1
else
Result := fix;
end;
function RoundIt(Val: Double; Lim: Double = 0.5): Double;
var //round real value Val up to next Lim value
fix: Integer; //e.g. 12.3 => 12.5, 12.6 => 13.0 (for Lim = 0.5)
frc: Double; //but 12.0 => 12.0, 12.5 => 12.5
begin
fix := Trunc(Val); //integer part
frc := Frac(Val);
if frc > Lim then begin //fractional part
Result := fix + 1.0;
end else begin
if frc > NADA then
Result := fix + Lim
else
Result := Val;
end;
end;
function StrEqual(Str1, Str2: string; Len: Integer = 0): Boolean;
begin //27.12.10 nk add - Return True if both strings are identical (not case-sensitive)
Str1 := LowerCase(Str1);
Str2 := LowerCase(Str2);
if Len < 0 then begin //12.10.12 nk add ff
Str1 := TrimEx(Str1); //compare strings w/o leading
Str2 := TrimEx(Str2); //and trailing white spaces
end;
if Len <= 0 then //12.10.12 nk old=Len = 0
Result := (Str1 = Str2)
else
Result := (LeftStr(Str1, Len) = LeftStr(Str2, Len));
end;
function StrContain(Str1, Str2: string): Boolean;
var //05.10.13 nk add - Return True if Str1 is part of Str2 (not case-sensitive)
part: string; //Str1 may be comma delimited (e.g. 'world,floor,scene')
begin
Result := False;
Str1 := LowerCase(Str1);
Str2 := LowerCase(Str2);
while StrCut(Str1, part) do //do NOT exit while loop
if Pos(part, Str2) > 0 then Result := True;
end;
function StrSplit(Input: string; Del: Char; Pos: Integer): string;
//22.01.10 nk opt - returns part of a string based on defined delimiter, such as ';'
// 1st part has Pos=0
// StrSplit('this is a test ', ' ', 1) = 'is' or
// StrSplit('data;another;yet;again;more;', ';', 2) = 'yet'
var
b, t: Integer;
buff: array of Integer;
begin
Result := cEMPTY;
if Input = cEMPTY then Exit;
t := CLEAR;
Input := Input + Del;
SetLength(buff, Length(Input));
for b := 0 to Pred(High(buff)) do begin
buff[b + 1] := PosEx(Del, Input, Succ(buff[b]));
if (buff[b + 1] < buff[b]) or (Pos < t) then
Break
else
Inc(t);
end;
try //do not trim - white spaces are valid
Result := Copy(Input, Succ(buff[Pos]), Pred(buff[Pos + 1] - buff[Pos]));
except
Result := cEMPTY; //22.01.10 nk add try..except (buff is empty if Input=Del)
end;
end;
function StrCut(Input: string; var Output: string; Del: Char = cCOMMA): Boolean;
var //09.10.12 nk add Del - returns comma delimited (trimmed) parts of an input string
i, l: Integer; //Unicode compliant - VALID_DELS = [',', ';', '|', '#'];
begin
if Input = cEMPTY then begin //20.05.11 nk add ff
Output := cEMPTY;
StringPart := cEMPTY;
Result := False;
Exit;
end;
if StringPart = Del then begin
StringPart := cEMPTY;
Result := False;
Exit;
end else begin //09.10.12 nk fix/add ff
if Length(StringPart) = 1 then begin
if CharInSet(StringPart[1], VALID_DELS) then
StringPart := cEMPTY;
end;
end;
if StringPart = cEMPTY then begin
StringPart := Input;
Output := cEMPTY;
end;
i := Pos(Del, StringPart);
l := Length(StringPart);
Result := (l > 0);
if i > 0 then begin
Output := TrimEx(LeftStr(StringPart, i - 1)); //06.11.11 nk old=Trim
if i = l then //05.07.08 nk opt (if last char is a comma)
StringPart := Del
else
StringPart := RightStr(StringPart, l - i); //06.11.11 nk old=Trim
end else begin
Output := TrimEx(StringPart);
StringPart := Del;
end;
end;
function StrVal(Instr, Substr: string; Del: Char = cCOMMA): Integer;
var //04.01.12 nk add - returns position value (0..n) of Substr in Instr (-1=not found)
subpos: Integer;
outstr: string;
begin
Result := NONE;
subpos := NONE;
while StrCut(Instr, outstr, Del) do begin //do NOT exit while loop
Inc(subpos);
if outstr = Substr then
Result := subpos;
end;
end;
function StrStrip(Input: string; StripChars: TCharSet): string; //28.07.10 nk add
var //xe//remove unwanted chars defined in StripChars from the Input string
i: Integer; //StripChars = ANSI character set
begin
Result := cEMPTY;
for i := 1 to Length(Input) do begin
if not CharInSet(Input[i], StripChars) then //xe//
Result := Result + Input[i];
end;
end;
function StrTrim(Input: string): string;
var //22.02.13 nk add - replace all control and white characters by one space
newword: Boolean;
i: Integer;
begin
Result := cEMPTY;
newword := False;
for i := 1 to Length(Input) do begin
if not CharInSet(Input[i], WHITE_CHARS) then begin
Result := Result + Input[i];
newword := True;
end else begin
if newword then
Result := Result + cSPACE;
newword := False;
end;
end;
end;
function StrCount(Input: string; Search: Char): Integer;
var //return number of matching characters in given string
i: Integer;
begin
Result := CLEAR;
for i := 1 to Length(Input) do
if Input[i] = Search then Inc(Result);
end;
function StrNum(Input: string): string;