-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathKOLadd.pas
3658 lines (3354 loc) · 102 KB
/
KOLadd.pas
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
//[START OF KOL.pas]
{****************************************************************
d d
KKKKK KKKKK OOOOOOOOO LLLLL d d
KKKKK KKKKK OOOOOOOOOOOOO LLLLL d d
KKKKK KKKKK OOOOO OOOOO LLLLL aaaa d d
KKKKK KKKKK OOOOO OOOOO LLLLL a d d
KKKKKKKKKK OOOOO OOOOO LLLLL a d d
KKKKK KKKKK OOOOO OOOOO LLLLL aaaaa dddddd dddddd
KKKKK KKKKK OOOOO OOOOO LLLLL a a d d d d
KKKKK KKKKK OOOOOOOOOOOOO LLLLLLLLLLLLL a a d d d d
KKKKK KKKKK OOOOOOOOO LLLLLLLLLLLLL aaaaa aa dddddd dddddd
Key Objects Library (C) 2000 by Kladov Vladimir.
//[VERSION]
****************************************************************
* VERSION 3.05+
****************************************************************
//[END OF VERSION]
The only reason why this part of KOL separated into another unit is that
Delphi has a restriction to DCU size exceeding which it is failed to debug
it normally and in attempt to execute code step by step an internal error
is occur which stops Delphi from working at all.
Version indicated above is a version of KOL, having place when KOLadd.pas was
modified last time, this is not a version of KOLadd itself.
}
//[UNIT DEFINES]
{$I KOLDEF.inc}
{$IFDEF EXTERNAL_KOLDEFS}
{$INCLUDE PROJECT_KOL_DEFS.INC}
{$ENDIF}
{$IFDEF EXTERNAL_DEFINES}
{$INCLUDE EXTERNAL_DEFINES.INC}
{$ENDIF EXTERNAL_DEFINES}
{$IFDEF INPACKAGE}
{$IFDEF _D2009orHigher}
{$DEFINE UNICODE_CTRLS}
{$ENDIF}
{$ENDIF}
unit KOLadd;
{
Define symbol TREE_NONAME to disallow using Name in TTree object.
Define symbol TREE_WIDE to use WideString for Name in TTree object.
}
interface
{$I KOLDEF.INC}
uses Windows, Messages, KOL;
{------------------------------------------------------------------------------)
| |
| T L i s t E x |
| |
(------------------------------------------------------------------------------}
type
PListEx = ^TListEx;
TListEx = object( TObj )
{* Extended list, with Objects[ ] property. Created calling NewListEx function. }
protected
fList: PList;
fObjects: PList;
function GetEx(Idx: Integer): Pointer;
procedure PutEx(Idx: Integer; const Value: Pointer);
function GetCount: Integer;
function GetAddBy: Integer;
procedure Set_AddBy(const Value: Integer);
public
destructor Destroy; virtual;
{* }
property AddBy: Integer read GetAddBy write Set_AddBy;
{* }
property Items[ Idx: Integer ]: Pointer read GetEx write PutEx;
{* }
property Count: Integer read GetCount;
{* }
procedure Clear;
{* }
procedure Add( Value: Pointer );
{* }
procedure AddObj( Value, Obj: Pointer );
{* }
procedure Insert( Idx: Integer; Value: Pointer );
{* }
procedure InsertObj( Idx: Integer; Value, Obj: Pointer );
{* }
procedure Delete( Idx: Integer );
{* }
procedure DeleteRange( Idx, Len: Integer );
{* }
function IndexOf( Value: Pointer ): Integer;
{* }
function IndexOfObj( Obj: Pointer ): Integer;
{* }
procedure Swap( Idx1, Idx2: Integer );
{* }
procedure MoveItem( OldIdx, NewIdx: Integer );
{* }
property ItemsList: PList read fList;
{* }
property ObjList: PList read fObjects;
{* }
function Last: Pointer;
{* }
function LastObj: Pointer;
{* }
end;
//[END OF TListEx DEFINITION]
//[NewListEx DECLARATION]
function NewListEx: PListEx;
{* Creates extended list. }
{------------------------------------------------------------------------------)
| |
| T B i t s |
| |
(------------------------------------------------------------------------------}
type
PBits = ^TBits;
TBits = object( TObj )
{* Variable-length bits array object. Created using function NewBits. See also
|<a href="kol_pas.htm#Small bit arrays (max 32 bits in array)">
Small bit arrays (max 32 bits in array)
|</a>. }
protected
fList: PList;
fCount: Integer;
function GetBit(Idx: Integer): Boolean;
procedure SetBit(Idx: Integer; const Value: Boolean);
function GetCapacity: Integer;
function GetSize: Integer;
procedure SetCapacity(const Value: Integer);
public
destructor Destroy; virtual;
{* }
property Bits[ Idx: Integer ]: Boolean read GetBit write SetBit;
{* }
property Size: Integer read GetSize;
{* Size in bytes of the array. To get know number of bits, use property Count. }
property Count: Integer read fCount;
{* Number of bits an the array. }
property Capacity: Integer read GetCapacity write SetCapacity;
{* Number of bytes allocated. Can be set before assigning bit values
to improve performance (minimizing amount of memory allocation
operations). }
function Copy( From, BitsCount: Integer ): PBits;
{* Use this property to get a sub-range of bits starting from given bit
and of BitsCount bits count. }
function IndexOf( Value: Boolean ): Integer;
{* Returns index of first bit with given value (True or False). }
function OpenBit: Integer;
{* Returns index of the first bit not set to true. }
procedure Clear;
{* Clears bits array. Count, Size and Capacity become 0. }
function LoadFromStream( strm: PStream ): Integer;
{* Loads bits from the stream. Data should be stored in the stream
earlier using SaveToStream method. While loading, previous bits
data are discarded and replaced with new one totally. In part,
Count of bits also is changed. Count of bytes read from the stream
while loading data is returned. }
function SaveToStream( strm: PStream ): Integer;
{* Saves entire array of bits to the stream. First, Count of bits
in the array is saved, then all bytes containing bits data. }
function Range( Idx, N: Integer ): PBits;
{* Creates and returns new TBits object instance containing N bits
starting from index Idx. If you call this method, you are responsible
for destroying returned object when it become not neccessary. }
procedure AssignBits( ToIdx: Integer; FromBits: PBits; FromIdx, N: Integer );
{* Assigns bits from another bits array object. N bits are assigned
starting at index ToIdx. }
procedure InstallBits( FromIdx, N: Integer; Value: Boolean );
{* Sets new Value for all bits in range [ FromIdx, FromIdx+Count-1 ]. }
function CountTrueBits: Integer;
{* Returns count of bits equal to TRUE. }
end;
//[END OF TBits DEFINITION]
//[NewBits DECLARATION]
function NewBits: PBits;
{* Creates variable-length bits array object. }
{------------------------------------------------------------------------------)
| |
| T F a s t S t r L i s t |
| |
(------------------------------------------------------------------------------}
type
PFastStrListEx = ^TFastStrListEx;
TFastStrListEx = object( TObj )
private
function GetItemLen(Idx: Integer): Integer;
function GetObject(Idx: Integer): DWORD;
procedure SetObject(Idx: Integer; const Value: DWORD);
function GetValues(AName: PAnsiChar): PAnsiChar;
protected
procedure Init; virtual;
protected
fList: PList;
fCount: Integer;
fCaseSensitiveSort: Boolean;
fTextBuf: PAnsiChar;
fTextSiz: DWORD;
fUsedSiz: DWORD;
protected
procedure ProvideSpace( AddSize: DWORD );
function Get(Idx: integer): AnsiString;
function GetTextStr: AnsiString;
procedure Put(Idx: integer; const Value: AnsiString);
procedure SetTextStr(const Value: AnsiString);
function GetPChars( Idx: Integer ): PAnsiChar;
destructor Destroy; virtual;
public
function AddAnsi( const S: AnsiString ): Integer;
{* Adds Ansi AnsiString to a list. }
function AddAnsiObject( const S: AnsiString; Obj: DWORD ): Integer;
{* Adds Ansi AnsiString and correspondent object to a list. }
function Add(S: PAnsiChar): integer;
{* Adds an AnsiString to list. }
function AddLen(S: PAnsiChar; Len: Integer): integer;
{* Adds an AnsiString to list. The AnsiString can contain #0 characters. }
public
FastClear: Boolean;
{* }
procedure Clear;
{* Makes AnsiString list empty. }
procedure Delete(Idx: integer);
{* Deletes AnsiString with given index (it *must* exist). }
function IndexOf(const S: AnsiString): integer;
{* Returns index of first AnsiString, equal to given one. }
function IndexOf_NoCase(const S: AnsiString): integer;
{* Returns index of first AnsiString, equal to given one (while comparing it
without case sensitivity). }
function IndexOfStrL_NoCase( Str: PAnsiChar; L: Integer ): integer;
{* Returns index of the first AnsiString, equal to given one (while comparing it
without case sensitivity). }
function Find(const S: AnsiString; var Index: Integer): Boolean;
{* Returns Index of the first AnsiString, equal or greater to given pattern, but
works only for sorted TFastStrListEx object. Returns TRUE if exact AnsiString found,
otherwise nearest (greater then a pattern) AnsiString index is returned,
and the result is FALSE. }
procedure InsertAnsi(Idx: integer; const S: AnsiString);
{* Inserts ANSI AnsiString before one with given index. }
procedure InsertAnsiObject(Idx: integer; const S: AnsiString; Obj: DWORD);
{* Inserts ANSI AnsiString before one with given index. }
procedure Insert(Idx: integer; S: PAnsiChar);
{* Inserts AnsiString before one with given index. }
procedure InsertLen( Idx: Integer; S: PAnsiChar; Len: Integer );
{* Inserts AnsiString from given PChar. It can contain #0 characters. }
function LoadFromFile(const FileName: AnsiString): Boolean;
{* Loads AnsiString list from a file. (If file does not exist, nothing
happens). Very fast even for huge text files. }
procedure LoadFromStream(Stream: PStream; Append2List: boolean);
{* Loads AnsiString list from a stream (from current position to the end of
a stream). Very fast even for huge text. }
procedure MergeFromFile(const FileName: AnsiString);
{* Merges AnsiString list with strings in a file. Fast. }
procedure Move(CurIndex, NewIndex: integer);
{* Moves AnsiString to another location. }
procedure SetText(const S: AnsiString; Append2List: boolean);
{* Allows to set strings of AnsiString list from given AnsiString (in which
strings are separated by $0D,$0A or $0D characters). Text can
contain #0 characters. Works very fast. This method is used in
all others, working with text arrays (LoadFromFile, MergeFromFile,
Assign, AddStrings). }
function SaveToFile(const FileName: AnsiString): Boolean;
{* Stores AnsiString list to a file. }
procedure SaveToStream(Stream: PStream);
{* Saves AnsiString list to a stream (from current position). }
function AppendToFile(const FileName: AnsiString): Boolean;
{* Appends strings of AnsiString list to the end of a file. }
property Count: integer read fCount;
{* Number of strings in a AnsiString list. }
property Items[Idx: integer]: AnsiString read Get write Put; default;
{* Strings array items. If item does not exist, empty AnsiString is returned.
But for assign to property, AnsiString with given index *must* exist. }
property ItemPtrs[ Idx: Integer ]: PAnsiChar read GetPChars;
{* Fast access to item strings as PChars. }
property ItemLen[ Idx: Integer ]: Integer read GetItemLen;
{* Length of AnsiString item. }
function Last: AnsiString;
{* Last item (or '', if AnsiString list is empty). }
property Text: AnsiString read GetTextStr write SetTextStr;
{* Content of AnsiString list as a single AnsiString (where strings are separated
by characters $0D,$0A). }
procedure Swap( Idx1, Idx2 : Integer );
{* Swaps to strings with given indeces. }
procedure Sort( CaseSensitive: Boolean );
{* Call it to sort AnsiString list. }
public
function AddObject( S: PAnsiChar; Obj: DWORD ): Integer;
{* Adds AnsiString S (null-terminated) with associated object Obj. }
function AddObjectLen( S: PAnsiChar; Len: Integer; Obj: DWORD ): Integer;
{* Adds AnsiString S of length Len with associated object Obj. }
procedure InsertObject( Idx: Integer; S: PAnsiChar; Obj: DWORD );
{* Inserts AnsiString S (null-terminated) at position Idx in the list,
associating it with object Obj. }
procedure InsertObjectLen( Idx: Integer; S: PAnsiChar; Len: Integer; Obj: DWORD );
{* Inserts AnsiString S of length Len at position Idx in the list,
associating it with object Obj. }
property Objects[ Idx: Integer ]: DWORD read GetObject write SetObject;
{* Access to objects associated with strings in the list. }
public
procedure Append( S: PAnsiChar );
{* Appends S (null-terminated) to the last AnsiString in FastStrListEx object, very fast. }
procedure AppendLen( S: PAnsiChar; Len: Integer );
{* Appends S of length Len to the last AnsiString in FastStrListEx object, very fast. }
procedure AppendInt2Hex( N: DWORD; MinDigits: Integer );
{* Converts N to hexadecimal and appends resulting AnsiString to the last
AnsiString, very fast. }
public
property Values[ Name: PAnsiChar ]: PAnsiChar read GetValues;
{* Returns a value correspondent to the Name an ini-file-like AnsiString list
(having Name1=Value1 Name2=Value2 etc. in each AnsiString). }
function IndexOfName( AName: PAnsiChar ): Integer;
{* Searches AnsiString starting from 'AName=' in AnsiString list like ini-file. }
end;
function NewFastStrListEx: PFastStrListEx;
{* Creates FastStrListEx object. }
var Upper: array[ Char ] of AnsiChar;
{* An table to convert char to uppercase very fast. First call InitUpper. }
Upper_Initialized: Boolean;
procedure InitUpper;
{* Call this fuction ones to fill Upper[ ] table before using it. }
type
PCABFile = ^TCABFile;
TOnNextCAB = function( Sender: PCABFile ): KOLString of object;
TOnCABFile = function( Sender: PCABFile; var FileName: KOLString ): Boolean of object;
{ ----------------------------------------------------------------------
TCabFile - windows cabinet files
----------------------------------------------------------------------- }
//[TCabFile DEFINITION]
TCABFile = object( TObj )
{* An object to simplify extracting files from a cabinet (.CAB) files.
The only what need to use this object, setupapi.dll. It is provided
with all latest versions of Windows. }
protected
FPaths: PKOLStrList;
FNames: PKOLStrList;
FOnNextCAB: TOnNextCAB;
FOnFile: TOnCABFile;
FTargetPath: KOLString;
FSetupapi: THandle;
function GetNames(Idx: Integer): KOLString;
function GetCount: Integer;
function GetPaths(Idx: Integer): KOLString;
function GetTargetPath: KOLString;
protected
FGettingNames: Boolean;
FCurCAB: Integer;
public
destructor Destroy; virtual;
{* }
property Paths[ Idx: Integer ]: KOLString read GetPaths;
{* A list of CAB-files. It is stored, when constructing function
OpenCABFile called. }
property Names[ Idx: Integer ]: KOLString read GetNames;
{* A list of file names, stored in a sequence of CAB files. To get know,
how many files are there, check Count property. }
property Count: Integer read GetCount;
{* Number of files stored in a sequence of CAB files. }
function Execute: Boolean;
{* Call this method to extract or enumerate files in CAB. For every
file, found during executing, event OnFile is alled (if assigned).
If the event handler (if any) does not provide full target path for
a file to extract to, property TargetPath is applyed (also if it
is assigned), or file is extracted to the default directory (usually
the same directory there CAB file is located, or current directory
- by a decision of the system).
|<br>
If a sequence of CAB files is used, and not all names for CAB files
are provided (absent or represented by a AnsiString '?' ), an event
OnNextCAB is called to obtain the name of the next CAB file.}
property CurCAB: Integer read FCurCAB;
{* Index of current CAB file in a sequence of CAB files. When OnNextCAB
event is called (if any), CurCAB property is already set to the
index of path, what should be provided. }
property OnNextCAB: TOnNextCAB read FOnNextCAB write FOnNextCAB;
{* This event is called, when a series of CAB files is needed and not
all CAB file names are provided (absent or represented by '?' AnsiString).
If this event is not assigned, the user is prompted to browse file. }
property OnFile: TOnCABFile read FOnFile write FOnFile;
{* This event is called for every file found during Execute method.
In an event handler (if any assigned), it is possible to return
False to skip file, or to provide another full target path for
file to extract it to, then default. If the event is not assigned,
all files are extracted either to default directory, or to the
directory TargetPath, if it is provided. }
property TargetPath: KOLString read GetTargetPath write FTargetPath;
{* Optional target directory to place there extracted files. }
end;
//[END OF TCABFile DEFINITION]
//[OpenCABFile DECLARATION]
function OpenCABFile( const APaths: array of AnsiString ): PCABFile;
{* This function creates TCABFile object, passing a sequence of CAB file names
(fully qualified). It is possible not to provide all names here, or pass '?'
AnsiString in place of some of those. For such files, either an event OnNextCAB
will be called, or (and) user will be prompted to browse file during
executing (i.e. Extracting). }
type
PDirChange = ^TDirChange;
{* }
TOnDirChange = procedure (Sender: PDirChange; const Path: KOLString) of object;
{* Event type to define OnChange event for folder monitoring objects. }
TFileChangeFilters = (fncFileName, fncDirName, fncAttributes, fncSize,
fncLastWrite, fncLastAccess, fncCreation, fncSecurity);
{* Possible change monitor filters. }
TFileChangeFilter = set of TFileChangeFilters;
{* Set of filters to pass to a constructor of TDirChange object. }
{ ----------------------------------------------------------------------
TDirChange object
----------------------------------------------------------------------- }
TDirChange = object(TObj)
{* Object type to monitor changes in certain folder. }
protected
{$IFDEF DIRCHG_ONEXECUTE}
FOnExecute: TOnEvent;
{$ENDIF}
FOnChange: TOnDirChange;
FHandle, FinEvent: THandle;
FPath: KOLString;
FMonitor: PThread;
FWatchSubtree: Boolean;
FDestroying: Boolean;
FFlags: DWORD;
function Execute( Sender: PThread ): Integer;
procedure Changed;
protected
destructor Destroy; virtual;
{*}
public
property Handle: THandle read FHandle;
{* Handle of file change notification object. *}
property Path: KOLString read FPath; //write SetPath;
{* Path to monitored folder (to a root, if tree of folders
is under monitoring). }
property OnChange: TOnDirChange read FOnChange write FOnChange;
{$IFDEF DIRCHG_ONEXECUTE}
property OnExecute: TOnEvent read FOnExecute write FOnExecute;
{$ENDIF}
end;
function NewDirChangeNotifier( const Path: KOLString; Filter: TFileChangeFilter;
WatchSubtree: Boolean; ChangeProc: TOnDirChange
{$IFDEF DIRCHG_ONEXECUTE} ; OnExecuteProc: TOnEvent
{$ENDIF} )
: PDirChange;
{* Creates notification object TDirChange. If something wrong (e.g.,
passed directory does not exist), nil is returned as a result. When change
is notified, ChangeProc is called always in main thread context.
(Please note, that ChangeProc can not be nil).
If empty filter is passed, default filter is used:
[fncFileName..fncLastWrite]. }
type
PMetafile = ^TMetafile;
{ ----------------------------------------------------------------------
TMetafile - Windows metafile and Enchanced Metafile image
----------------------------------------------------------------------- }
TMetafile = object( TObj )
{* Object type to incapsulate metafile image. }
protected
function GetHeight: Integer;
function GetWidth: Integer;
procedure SetHandle(const Value: THandle);
protected
fHandle: THandle;
fHeader: PEnhMetaHeader;
procedure RetrieveHeader;
public
destructor Destroy; virtual;
{* }
procedure Clear;
{* }
function Empty: Boolean;
{* Returns TRUE if empty}
property Handle: THandle read fHandle write SetHandle;
{* Returns handle of enchanced metafile. }
function LoadFromStream( Strm: PStream ): Boolean;
{* Loads emf or wmf file format from stream. }
function LoadFromFile( const Filename: AnsiString ): Boolean;
{* Loads emf or wmf from stream. }
procedure Draw( DC: HDC; X, Y: Integer );
{* Draws enchanced metafile on DC. }
procedure StretchDraw( DC: HDC; const R: TRect );
{* Draws enchanced metafile stretched. }
property Width: Integer read GetWidth;
{* Native width of the metafile. }
property Height: Integer read GetHeight;
{* Native height of the metafile. }
end;
//[END OF TMetafile DEFINITION]
//[NewMetafile DECLARATION]
function NewMetafile: PMetafile;
{* Creates metafile object. }
//[Metafile CONSTANTS, STRUCTURES, ETC.]
const
WMFKey = Integer($9AC6CDD7);
WMFWord = $CDD7;
type
TMetafileHeader = packed record
Key: Longint;
Handle: SmallInt;
Box: TSmallRect;
Inch: Word;
Reserved: Longint;
CheckSum: Word;
end;
function ComputeAldusChecksum(var WMF: TMetafileHeader): Word;
{++}(*
function SetEnhMetaFileBits(p1: UINT; p2: PAnsiChar): HENHMETAFILE; stdcall;
function PlayEnhMetaFile(DC: HDC; p2: HENHMETAFILE; const p3: TRect): BOOL; stdcall;
*){--}
// NewActionList, TAction - by Yury Sidorov
//[ACTIONS OBJECT]
{ ----------------------------------------------------------------------
TAction and TActionList
----------------------------------------------------------------------- }
type
PControlRec = ^TControlRec;
TOnUpdateCtrlEvent = procedure(Sender: PControlRec) of object;
TCtrlKind = (ckControl, ckMenu, ckToolbar);
TControlRec = record
Ctrl: PObj;
CtrlKind: TCtrlKind;
ItemID: integer;
UpdateProc: TOnUpdateCtrlEvent;
end;
PAction = ^TAction;
PActionList = ^TActionList;
TAction = object( TObj )
{*! Use action objects, in conjunction with action lists, to centralize the response
to user commands (actions).
Use AddControl, AddMenuItem, AddToolbarButton methods to link controls to an action.
See also TActionList.
}
protected
FControls: PList;
FCaption: KOLString;
FChecked: boolean;
FVisible: boolean;
FEnabled: boolean;
FHelpContext: integer;
FHint: KOLString;
FOnExecute: TOnEvent;
FAccelerator: TMenuAccelerator;
FShortCut: KOLString;
procedure DoOnMenuItem(Sender: PMenu; Item: Integer);
procedure DoOnToolbarButtonClick(Sender: PControl; BtnID: Integer);
procedure DoOnControlClick(Sender: PObj);
procedure SetCaption(const Value: KOLString);
procedure SetChecked(const Value: boolean);
procedure SetEnabled(const Value: boolean);
procedure SetHelpContext(const Value: integer);
procedure SetHint(const Value: KOLString);
procedure SetVisible(const Value: boolean);
procedure SetAccelerator(const Value: TMenuAccelerator);
procedure UpdateControls;
procedure LinkCtrl(ACtrl: PObj; ACtrlKind: TCtrlKind; AItemID: integer; AUpdateProc: TOnUpdateCtrlEvent);
procedure SetOnExecute(const Value: TOnEvent);
procedure UpdateCtrl(Sender: PControlRec);
procedure UpdateMenu(Sender: PControlRec);
procedure UpdateToolbar(Sender: PControlRec);
public
destructor Destroy; virtual;
procedure LinkControl(Ctrl: PControl);
{* Add a link to a TControl or descendant control. }
procedure LinkMenuItem(Menu: PMenu; MenuItemIdx: integer);
{* Add a link to a menu item. }
procedure LinkToolbarButton(Toolbar: PControl; ButtonIdx: integer);
{* Add a link to a toolbar button. }
procedure Execute;
{* Executes a OnExecute event handler. }
property Caption: KOLString read FCaption write SetCaption;
{* Text caption. }
property Hint: KOLString read FHint write SetHint;
{* Hint (tooltip). Currently used for toolbar buttons only. }
property Checked: boolean read FChecked write SetChecked;
{* Checked state. }
property Enabled: boolean read FEnabled write SetEnabled;
{* Enabled state. }
property Visible: boolean read FVisible write SetVisible;
{* Visible state. }
property HelpContext: integer read FHelpContext write SetHelpContext;
{* Help context. }
property Accelerator: TMenuAccelerator read FAccelerator write SetAccelerator;
{* Accelerator for menu items. }
property OnExecute: TOnEvent read FOnExecute write SetOnExecute;
{* This event is executed when user clicks on a linked object or Execute method was called. }
end;
TActionList = object( TObj )
{*! TActionList maintains a list of actions used with components and controls,
such as menu items and buttons.
Action lists are used, in conjunction with actions, to centralize the response
to user commands (actions).
Write an OnUpdateActions handler to update actions state.
Created using function NewActionList.
See also TAction.
}
protected
FOwner: PControl;
FActions: PList;
FOnUpdateActions: TOnEvent;
function GetActions(Idx: integer): PAction;
function GetCount: integer;
protected
procedure DoUpdateActions(Sender: PObj);
public
destructor Destroy; virtual;
function Add(const ACaption, AHint: KOLString; OnExecute: TOnEvent): PAction;
{* Add a new action to the list. Returns pointer to action object. }
procedure Delete(Idx: integer);
{* Delete action by index from list. }
procedure Clear;
{* Clear all actions in the list. }
property Actions[Idx: integer]: PAction read GetActions;
{* Access to actions in the list. }
property Count: integer read GetCount;
{* Number of actions in the list.. }
property OnUpdateActions: TOnEvent read FOnUpdateActions write FOnUpdateActions;
{* Event handler to update actions state. This event is called each time when application
goes in the idle state (no messages in the queue). }
end;
function NewActionList(AOwner: PControl): PActionList;
{* Action list constructor. AOwner - owner form. }
{ -- tree (non-visual) -- }
type
PTree = ^TTree;
TTree = object( TObj )
{* Object to store tree-like data in memory (non-visual). }
protected
fParent: PTree;
fChildren: PList;
fPrev: PTree;
fNext: PTree;
{$IFDEF TREE_NONAME}
{$ELSE}
{$IFDEF TREE_WIDE}
fNodeName: WideString;
{$ELSE}
fNodeName: AnsiString;
{$ENDIF}
{$ENDIF}
fData: Pointer;
function GetCount: Integer;
function GetItems(Idx: Integer): PTree;
procedure Unlink;
function GetRoot: PTree;
function GetLevel: Integer;
function GetTotal: Integer;
function GetIndexAmongSiblings: Integer;
protected
{$IFDEF USE_CONSTRUCTORS}
constructor CreateTree( AParent: PTree; const AName: AnsiString );
{* }
{$ENDIF}
destructor Destroy; virtual;
{* }
procedure Init; virtual;
public
procedure Clear;
{* Destoyes all child nodes. }
{$IFDEF TREE_NONAME}
{$ELSE}
{$IFDEF TREE_WIDE}
property Name: WideString read fNodeName write fNodeName;
{$ELSE}
property Name: AnsiString read fNodeName write fNodeName;
{$ENDIF}
{$ENDIF}
{* Optional node name. }
property Data: Pointer read fData write fData;
{* Optional user-defined pointer. }
property Count: Integer read GetCount;
{* Number of child nodes of given node. }
property Items[ Idx: Integer ]: PTree read GetItems;
{* Child nodes list items. }
procedure Add( Node: PTree );
{* Adds another node as a child of given tree node. This operation
as well as Insert can be used to move node together with its children
to another location of the same tree or even from another tree.
Anyway, added Node first correctly removed from old place (if it is
defined for it). But for simplest task, such as filling of tree with
nodes, code should looking as follows:
! Node := NewTree( nil, 'test of creating node without parent' );
! RootOfMyTree.Add( Node );
Though, this code gives the same result as:
! Node := NewTree( RootOfMyTree, 'test of creatign node as a child' ); }
procedure Insert( Before, Node: PTree );
{* Inserts earlier created 'Node' just before given child node 'Before'
as a child of given tree node. See also Add method. }
property Parent: PTree read fParent;
{* Returns parent node (or nil, if there is no parent). }
property Index: Integer read GetIndexAmongSiblings;
{* Returns an index of the node in a list of nodes of the same parent
(or -1, if Parent is not defined). }
property PrevSibling: PTree read fPrev;
{* Returns previous node in a list of children of the Parent. Nil is
returned, if given node is the first child of the Parent or has
no Parent. }
property NextSibling: PTree read fNext;
{* Returns next node in a list of children of the Parent. Nil is returned,
if given node is the last child of the Parent or has no Parent at all. }
property Root: PTree read GetRoot;
{* Returns root node (i.e. the last Parent, enumerating parents recursively). }
property Level: Integer read GetLevel;
{* Returns level of the node, i.e. integer value, equal to 0 for root
of a tree, 1 for its children, etc. }
property Total: Integer read GetTotal;
{* Returns total number of children of the node and all its children
counting its recursively (but node itself is not considered, i.e.
Total for node without children is equal to 0). }
procedure SortByName;
{* Sorts children of the node in ascending order. Sorting is not
recursive, i.e. only immediate children are sorted. }
procedure SwapNodes( i1, i2: Integer );
{* Swaps two child nodes. }
function IsParentOfNode( Node: PTree ): Boolean;
{* Returns true, if Node is the tree itself or is a parent of the given node
on any level. }
function IndexOf( Node: PTree ): Integer;
{* Total index of the child node (on any level under this node). }
end;
//[END OF TTree DEFINITION]
//[NewTree DECLARATION]
{$IFDEF TREE_NONAME}
function NewTree( AParent: PTree ): PTree;
{* Nameless version (for case when TREE_NONAME symbol is defined).
Constructs tree node, adding it to the end of children list of
the AParent. If AParent is nil, new root tree node is created. }
{$ELSE}
{$IFDEF TREE_WIDE}
function NewTree( AParent: PTree; const AName: WideString ): PTree;
{* WideString version (for case when TREE_WIDE symbol is defined).
Constructs tree node, adding it to the end of children list of
the AParent. If AParent is nil, new root tree node is created. }
{$ELSE}
function NewTree( AParent: PTree; const AName: AnsiString ): PTree;
{* Constructs tree node, adding it to the end of children list of
the AParent. If AParent is nil, new root tree node is created. }
{$ENDIF}
{$ENDIF}
{-------------------------------------------------------------------------------
ADDITIONAL UTILITIES
}
function MapFileRead( const Filename: AnsiString; var hFile, hMap: THandle ): Pointer;
{* Opens file for read only (with share deny none attribute) and maps its
entire content using memory mapped files technique. The address of the
first byte of file mapped into the application address space is returned.
When mapping no more needed, it must be closed calling UnmapFile (see below).
Maximum file size which can be mapped at a time is 1/4 Gigabytes. If file size
exceeding this value only 1/4 Gigabytes starting from the beginning of the
file is mapped therefore. }
function MapFile( const Filename: AnsiString; var hFile, hMap: THandle ): Pointer;
{* Opens file for read/write (in exlusive mode) and maps its
entire content using memory mapped files technique. The address of the
first byte of file mapped into the application address space is returned.
When mapping no more needed, it must be closed calling UnmapFile (see below). }
procedure UnmapFile( BasePtr: Pointer; hFile, hMap: THandle );
{* Closes mapping opened via MapFile or MapFileRead call. }
//------------------------ for MCK projects:
{$IFDEF KOL_MCK}
type
TKOLAction = PAction;
TKOLActionList = PActionList;
{$ENDIF}
function ShowQuestion( const S: KOLString; Answers: KOLString ): Integer;
{* Modal dialog like ShowMsgModal. It is based on KOL form, so it can
be called also out of message loop, e.g. after finishing the
application. Also, this function *must* be used in MDI applications
in place of any dialog functions, based on MessageBox.
|<br>
The the second parameter should be empty AnsiString or several possible
answers separated by '/', e.g.: 'Yes/No/Cancel'. Result is
a number answered, starting from 1. For example, if 'Cancel'
was pressed, 3 will be returned.
|<br>
User can also press ESCAPE key, or close modal dialog. In such case
-1 is returned. }
function ShowQuestionEx( S: KOLString; Answers: KOLString; CallBack: TOnEvent ): Integer;
{* Like ShowQuestion, but with CallBack function, called just before showing
the dialog. }
procedure ShowMsgModal( const S: KOLString );
{* This message function can be used out of a message loop (e.g., after
finishing the application). It is always modal.
Actually, a form with word-wrap label (decorated as borderless edit
box with btnFace color) and with OK button is created and shown modal.
When a dialog is called from outside message loop, caption 'Information'
is always displayed.
Dialog form is automatically resized vertically to fit message text
(but until screen height is achieved) and shown always centered on
screen. The width is fixed (400 pixels).
|<br>
Do not use this function outside the message loop for case, when the
Applet variable is not used in an application. }
implementation
//uses
//ShellAPI,
//shlobj,
//{$IFNDEF _D2}ActiveX,{$ENDIF}
// CommDlg
{$IFDEF USE_GRUSH}uses ToGrush; {$ENDIF}
{------------------------------------------------------------------------------)
| |
| T L i s t E x |
| |
(------------------------------------------------------------------------------}
{ TListEx }
function NewListEx: PListEx;
begin
new( Result, Create );
Result.fList := NewList;
Result.fObjects := NewList;
end;
procedure TListEx.Add(Value: Pointer);
begin
AddObj( Value, nil );
end;
procedure TListEx.AddObj(Value, Obj: Pointer);
var C: Integer;
begin
C := Count;
fList.Add( Value );
fObjects.Insert( C, Obj );
end;
procedure TListEx.Clear;
begin
fList.Clear;
fObjects.Clear;
end;
//[procedure TListEx.Delete]
procedure TListEx.Delete(Idx: Integer);
begin
DeleteRange( Idx, 1 );
end;
//[procedure TListEx.DeleteRange]
procedure TListEx.DeleteRange(Idx, Len: Integer);
begin
fList.DeleteRange( Idx, Len );
fObjects.DeleteRange( Idx, Len );
end;
//[destructor TListEx.Destroy]
destructor TListEx.Destroy;
begin
fList.Free;
fObjects.Free;
inherited;
end;
//[function TListEx.GetAddBy]
function TListEx.GetAddBy: Integer;
begin
Result := fList.AddBy;
end;
//[function TListEx.GetCount]
function TListEx.GetCount: Integer;
begin
Result := fList.Count;
end;
//[function TListEx.GetEx]
function TListEx.GetEx(Idx: Integer): Pointer;
begin
Result := fList.Items[ Idx ];
end;
//[function TListEx.IndexOf]
function TListEx.IndexOf(Value: Pointer): Integer;
begin
Result := fList.IndexOf( Value );
end;
//[function TListEx.IndexOfObj]
function TListEx.IndexOfObj(Obj: Pointer): Integer;
begin
Result := fObjects.IndexOf( Obj );
end;
//[procedure TListEx.Insert]
procedure TListEx.Insert(Idx: Integer; Value: Pointer);
begin
InsertObj( Idx, Value, nil );
end;
//[procedure TListEx.InsertObj]
procedure TListEx.InsertObj(Idx: Integer; Value, Obj: Pointer);
begin
fList.Insert( Idx, Value );
fObjects.Insert( Idx, Obj );
end;
//[function TListEx.Last]
function TListEx.Last: Pointer;
begin
Result := fList.Last;
end;
//[function TListEx.LastObj]
function TListEx.LastObj: Pointer;
begin
Result := fObjects.Last;
end;
//[procedure TListEx.MoveItem]
procedure TListEx.MoveItem(OldIdx, NewIdx: Integer);
begin
fList.MoveItem( OldIdx, NewIdx );
fObjects.MoveItem( OldIdx, NewIdx );
end;
//[procedure TListEx.PutEx]
procedure TListEx.PutEx(Idx: Integer; const Value: Pointer);
begin
fList.Items[ Idx ] := Value;
end;
//[procedure TListEx.Set_AddBy]
procedure TListEx.Set_AddBy(const Value: Integer);
begin
fList.AddBy := Value;
fObjects.AddBy := Value;
end;
//[procedure TListEx.Swap]
procedure TListEx.Swap(Idx1, Idx2: Integer);
begin
fList.Swap( Idx1, Idx2 );
fObjects.Swap( Idx1, Idx2 );
end;
{------------------------------------------------------------------------------)
| |
| T B i t s |
| |
(------------------------------------------------------------------------------}
{ TBits }
type