-
Notifications
You must be signed in to change notification settings - Fork 0
/
uPSUtils.pas
1729 lines (1493 loc) · 37.2 KB
/
uPSUtils.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
unit uPSUtils;
{$I PascalScript.inc}
interface
uses
Classes, SysUtils {$IFDEF VER130}, Windows {$ENDIF};
const
PSMainProcName = '!MAIN';
PSMainProcNameOrg = 'Main Proc';
PSLowBuildSupport = 12;
PSCurrentBuildNo = 23;
PSCurrentversion = '1.31';
PSValidHeader = 1397769801;
PSAddrStackStart = 1610612736;
PSAddrNegativeStackStart = 1073741824;
type
TbtString = {$IFDEF DELPHI2009UP}AnsiString{$ELSE}String{$ENDIF};
TPSBaseType = Byte;
TPSVariableType = (ivtGlobal, ivtParam, ivtVariable);
const
btReturnAddress = 0;
btU8 = 1;
btS8 = 2;
btU16 = 3;
btS16 = 4;
btU32 = 5;
btS32 = 6;
btSingle = 7;
btDouble = 8;
btExtended = 9;
btString = 10;
btRecord = 11;
btArray = 12;
btPointer = 13;
btPChar = 14;
btResourcePointer = 15;
btVariant = 16;
{$IFNDEF PS_NOINT64}
btS64 = 17;
{$ENDIF}
btChar = 18;
{$IFNDEF PS_NOWIDESTRING}
btWideString = 19;
btWideChar = 20;
{$ENDIF}
btProcPtr = 21;
btStaticArray = 22;
btSet = 23;
btCurrency = 24;
btClass = 25;
btInterface = 26;
btNotificationVariant = 27;
btUnicodeString = 28;
btType = 130;
btEnum = 129;
btExtClass = 131;
function MakeHash(const s: TbtString): Longint;
const
{ Script internal command: Assign command<br>
Command: TPSCommand;<br>
VarDest, // no data<br>
VarSrc: TPSVariable;<br>
}
CM_A = 0;
{ Script internal command: Calculate Command<br>
Command: TPSCommand; <br>
CalcType: Byte;<br>
<i><br>
0 = +<br>
1 = -<br>
2 = *<br>
3 = /<br>
4 = MOD<br>
5 = SHL<br>
6 = SHR<br>
7 = AND<br>
8 = OR<br>
9 = XOR<br>
</i><br>
VarDest, // no data<br>
VarSrc: TPSVariable;<br>
<br>
}
CM_CA = 1;
{ Script internal command: Push<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
CM_P = 2;
{ Script internal command: Push Var<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
CM_PV = 3;
{ Script internal command: Pop<br>
Command: TPSCommand; <br>
}
CM_PO = 4;
{ Script internal command: Call<br>
Command: TPSCommand; <br>
ProcNo: Longword;<br>
}
Cm_C = 5;
{ Script internal command: Goto<br>
Command: TPSCommand; <br>
NewPosition: Longint; //relative to end of this instruction<br>
}
Cm_G = 6;
{ Script internal command: Conditional Goto<br>
Command: TPSCommand; <br>
NewPosition: LongWord; //relative to end of this instruction<br>
Var: TPSVariable; // no data<br>
}
Cm_CG = 7;
{ Script internal command: Conditional NOT Goto<br>
Command: TPSCommand; <br>
NewPosition: LongWord; // relative to end of this instruction<br>
Var: TPSVariable; // no data<br>
}
Cm_CNG = 8;
{ Script internal command: Ret<br>
Command: TPSCommand; <br>
}
Cm_R = 9;
{ Script internal command: Set Stack Type<br>
Command: TPSCommand; <br>
NewType: LongWord;<br>
OffsetFromBase: LongWord;<br>
}
Cm_ST = 10;
{ Script internal command: Push Type<br>
Command: TPSCommand; <br>
FType: LongWord;<br>
}
Cm_Pt = 11;
{ Script internal command: Compare<br>
Command: TPSCommand; <br>
CompareType: Byte;<br>
<i><br>
0 = >=<br>
1 = <=<br>
2 = ><br>
3 = <<br>
4 = <><br>
5 = =<br>
<i><br>
IntoVar: TPSAssignment;<br>
Compare1, Compare2: TPSAssigment;<br>
}
CM_CO = 12;
{ Script internal command: Call Var<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
Cm_cv = 13;
{ Script internal command: Set Pointer<br>
Command: TPSCommand; <br>
VarDest: TPSVariable;<br>
VarSrc: TPSVariable;<br>
}
cm_sp = 14;
{ Script internal command: Boolean NOT<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
cm_bn = 15;
{ Script internal command: Var Minus<br>
Command: TPSCommand; <br>
Var: TPSVariable;
}
cm_vm = 16;
{ Script internal command: Set Flag<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
DoNot: Boolean;<br>
}
cm_sf = 17;
{ Script internal command: Flag Goto<br>
Command: TPSCommand; <br>
Where: Cardinal;<br>
}
cm_fg = 18;
{ Script internal command: Push Exception Handler<br>
Command: TPSCommand; <br>
FinallyOffset,<br>
ExceptionOffset, // FinallyOffset or ExceptionOffset need to be set.<br>
Finally2Offset,<br>
EndOfBlock: Cardinal;<br>
}
cm_puexh = 19;
{ Script internal command: Pop Exception Handler<br>
Command:TPSCommand; <br>
Position: Byte;<br>
<i> 0 = end of try/finally/exception block;<br>
1 = end of first finally<br>
2 = end of except<br>
3 = end of second finally<br>
</i><br>
}
cm_poexh = 20;
{ Script internal command: Integer NOT<br>
Command: TPSCommand; <br>
Where: Cardinal;<br>
}
cm_in = 21;
{Script internal command: Set Stack Pointer To Copy<br>
Command: TPSCommand; <br>
Where: Cardinal;<br>
}
cm_spc = 22;
{Script internal command: Inc<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
cm_inc = 23;
{Script internal command: Dec<br>
Command: TPSCommand; <br>
Var: TPSVariable;<br>
}
cm_dec = 24;
{Script internal command: nop<br>
Command: TPSCommand; <br>}
cm_nop = 255;
{ Script internal command: Pop and Goto<br>
Command: TPSCommand; <br>
NewPosition: Longint; //relative to end of this instruction<br>
}
Cm_PG = 25;
{ Script internal command: Pop*2 and Goto<br>
Command: TPSCommand; <br>
NewPosition: Longint; //relative to end of this instruction<br>
}
Cm_P2G = 26;
type
TbtU8 = Byte;
TbtS8 = ShortInt;
TbtU16 = Word;
TbtS16 = SmallInt;
TbtU32 = Cardinal;
TbtS32 = Longint;
TbtSingle = Single;
TbtDouble = double;
TbtExtended = Extended;
tbtCurrency = Currency;
{$IFNDEF PS_NOINT64}
tbts64 = int64;
{$ENDIF}
tbtchar = {$IFDEF DELPHI4UP}AnsiChar{$ELSE}CHAR{$ENDIF};
{$IFNDEF PS_NOWIDESTRING}
tbtwidestring = widestring;
tbtunicodestring = {$IFDEF DELPHI2009UP}UnicodeString{$ELSE}widestring{$ENDIF};
tbtwidechar = widechar;
tbtNativeString = {$IFDEF DELPHI2009UP}tbtUnicodeString{$ELSE}tbtString{$ENDIF};
{$ENDIF}
{$IFDEF FPC}
IPointer = PtrUInt;
{$ELSE}
{$IFDEF CPU64} IPointer = LongWord;{$ELSE} IPointer = Cardinal;{$ENDIF}
{$ENDIF}
TPSCallingConvention = (cdRegister, cdPascal, cdCdecl, cdStdCall, cdSafeCall);
const
PointerSize = IPointer({$IFDEF CPU64}8{$ELSE}4{$ENDIF});
PointerSize2 = IPointer(2*PointerSize);
MaxListSize = Maxint div 16;
type
PPointerList = ^TPointerList;
TPointerList = array[0..MaxListSize - 1] of Pointer;
TPSList = class(TObject)
protected
FData: PPointerList;
FCapacity: Cardinal;
FCount: Cardinal;
FCheckCount: Cardinal;
private
function GetItem(Nr: Cardinal): Pointer;
procedure SetItem(Nr: Cardinal; P: Pointer);
public
{$IFNDEF PS_NOSMARTLIST}
procedure Recreate;
{$ENDIF}
property Data: PPointerList read FData;
constructor Create;
function IndexOf(P: Pointer): Longint;
destructor Destroy; override;
property Count: Cardinal read FCount;
property Items[nr: Cardinal]: Pointer read GetItem write SetItem; default;
function Add(P: Pointer): Longint;
procedure AddBlock(List: PPointerList; Count: Longint);
procedure Remove(P: Pointer);
procedure Delete(Nr: Cardinal);
procedure DeleteLast;
procedure Clear; virtual;
end;
TIFList = TPSList;
TPSStringList = class(TObject)
private
List: TPSList;
function GetItem(Nr: LongInt): TbtString;
procedure SetItem(Nr: LongInt; const s: TbtString);
public
function Count: LongInt;
property Items[Nr: Longint]: TbtString read GetItem write SetItem; default;
procedure Add(const P: TbtString);
procedure Delete(NR: LongInt);
procedure Clear;
constructor Create;
destructor Destroy; override;
end;
TIFStringList = TPsStringList;
TPSUnitList = class;
TPSUnit = class(TObject)
private
fList : TPSUnitList;
fUnits : TPSList;
fUnitName : TbtString;
procedure SetUnitName(const Value: TbtString);
public
constructor Create(List: TPSUnitList);
destructor Destroy; override;
procedure AddUses(pUnitName: TbtString);
function HasUses(pUnitName: TbtString): Boolean;
property UnitName: TbtString read fUnitName write SetUnitName;
end;
TPSUnitList = class
private
fList: TPSList;
function Add: TPSUnit;
public
constructor Create;
function GetUnit(UnitName: TbtString): TPSUnit;
destructor Destroy; override;
end;
type
TPSPasToken = (
CSTI_EOF,
CSTIINT_Comment,
CSTIINT_WhiteSpace,
CSTI_Identifier,
CSTI_SemiColon,
CSTI_Comma,
CSTI_Period,
CSTI_Colon,
CSTI_OpenRound,
CSTI_CloseRound,
CSTI_OpenBlock,
CSTI_CloseBlock,
CSTI_Assignment,
CSTI_Equal,
CSTI_NotEqual,
CSTI_Greater,
CSTI_GreaterEqual,
CSTI_Less,
CSTI_LessEqual,
CSTI_Plus,
CSTI_Minus,
CSTI_Divide,
CSTI_Multiply,
CSTI_Integer,
CSTI_Real,
CSTI_String,
CSTI_Char,
CSTI_HexInt,
CSTI_AddressOf,
CSTI_Dereference,
CSTI_TwoDots,
CSTII_and,
CSTII_array,
CSTII_begin,
CSTII_case,
CSTII_const,
CSTII_div,
CSTII_do,
CSTII_downto,
CSTII_else,
CSTII_end,
CSTII_for,
CSTII_function,
CSTII_if,
CSTII_in,
CSTII_mod,
CSTII_not,
CSTII_of,
CSTII_or,
CSTII_procedure,
CSTII_program,
CSTII_repeat,
CSTII_record,
CSTII_set,
CSTII_shl,
CSTII_shr,
CSTII_then,
CSTII_to,
CSTII_type,
CSTII_until,
CSTII_uses,
CSTII_var,
CSTII_while,
CSTII_with,
CSTII_xor,
CSTII_exit,
CSTII_class,
CSTII_constructor,
CSTII_destructor,
CSTII_inherited,
CSTII_private,
CSTII_public,
CSTII_published,
CSTII_protected,
CSTII_property,
CSTII_virtual,
CSTII_override,
//CSTII_default, //Birb
CSTII_As,
CSTII_Is,
CSTII_Unit,
CSTII_Try,
CSTII_Except,
CSTII_Finally,
CSTII_External,
CSTII_Forward,
CSTII_Export,
CSTII_Label,
CSTII_Goto,
CSTII_Chr,
CSTII_Ord,
CSTII_Interface,
CSTII_Implementation,
CSTII_initialization, //* Nvds
CSTII_finalization, //* Nvds
CSTII_out,
CSTII_nil
);
TPSParserErrorKind = (iNoError
, iCommentError
, iStringError
, iCharError
, iSyntaxError
);
TPSParserErrorEvent = procedure (Parser: TObject; Kind: TPSParserErrorKind) of object;
TPSPascalParser = class(TObject)
protected
FData: TbtString;
FText: {$IFDEF DELPHI4UP}PAnsiChar{$ELSE}PChar{$ENDIF};
FLastEnterPos, FRow, FRealPosition, FTokenLength: Cardinal;
FTokenId: TPSPasToken;
FToken: TbtString;
FOriginalToken: TbtString;
FParserError: TPSParserErrorEvent;
FEnableComments: Boolean;
FEnableWhitespaces: Boolean;
function GetCol: Cardinal;
// only applicable when Token in [CSTI_Identifier, CSTI_Integer, CSTI_Real, CSTI_String, CSTI_Char, CSTI_HexInt]
public
property EnableComments: Boolean read FEnableComments write FEnableComments;
property EnableWhitespaces: Boolean read FEnableWhitespaces write FEnableWhitespaces;
procedure Next; virtual;
property GetToken: TbtString read FToken;
property OriginalToken: TbtString read FOriginalToken;
property CurrTokenPos: Cardinal read FRealPosition;
property CurrTokenID: TPSPasToken read FTokenId;
property Row: Cardinal read FRow;
property Col: Cardinal read GetCol;
procedure SetText(const Data: TbtString); virtual;
property OnParserError: TPSParserErrorEvent read FParserError write FParserError;
end;
function FloatToStr(E: Extended): TbtString;
function FastLowerCase(const s: TbtString): TbtString;
function Fw(const S: TbtString): TbtString;
function IntToStr(I: LongInt): TbtString;
function StrToIntDef(const S: TbtString; Def: LongInt): LongInt;
function StrToInt(const S: TbtString): LongInt;
function StrToFloat(const s: TbtString): Extended;
function FastUpperCase(const s: TbtString): TbtString;
function GRFW(var s: TbtString): TbtString;
function GRLW(var s: TbtString): TbtString;
const
FCapacityInc = 32;
{$IFNDEF PS_NOSMARTLIST}
FMaxCheckCount = (FCapacityInc div 4) * 64;
{$ENDIF}
{$IFDEF VER130}
function WideUpperCase(const S: WideString): WideString;
function WideLowerCase(const S: WideString): WideString;
{$ENDIF}
implementation
{$IFDEF DELPHI3UP }
resourceString
{$ELSE }
const
{$ENDIF }
RPS_InvalidFloat = 'Invalid float';
{$IFDEF VER130}
function WideUpperCase(const S: WideString): WideString;
var
Len: Integer;
begin
// CharUpperBuffW is stubbed out on Win9x platofmrs
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
Len := Length(S);
SetString(Result, PWideChar(S), Len);
if Len > 0 then CharUpperBuffW(Pointer(Result), Len);
end
else
Result := AnsiUpperCase(S);
end;
function WideLowerCase(const S: WideString): WideString;
var
Len: Integer;
begin
// CharLowerBuffW is stubbed out on Win9x platofmrs
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
Len := Length(S);
SetString(Result, PWideChar(S), Len);
if Len > 0 then CharLowerBuffW(Pointer(Result), Len);
end
else
Result := AnsiLowerCase(S);
end;
{$ENDIF}
function MakeHash(const s: TbtString): Longint;
{small hash maker}
var
I: Integer;
begin
Result := 0;
for I := 1 to Length(s) do
Result := ((Result shl 7) or (Result shr 25)) + Ord(s[I]);
end;
function GRFW(var s: TbtString): TbtString;
var
l: Longint;
begin
l := 1;
while l <= Length(s) do
begin
if s[l] = ' ' then
begin
Result := copy(s, 1, l - 1);
Delete(s, 1, l);
exit;
end;
l := l + 1;
end;
Result := s;
s := '';
end;
function GRLW(var s: TbtString): TbtString;
var
l: Longint;
begin
l := Length(s);
while l >= 1 do
begin
if s[l] = ' ' then
begin
Result := copy(s, l+1, MaxInt);
Delete(s, l, MaxInt);
exit;
end;
Dec(l);
end;
Result := s;
s := '';
end;
function StrToFloat(const s: TbtString): Extended;
var
i: longint;
begin
Val(string(s), Result, i);
if i <> 0 then raise Exception.Create(RPS_InvalidFloat);
end;
//-------------------------------------------------------------------
function IntToStr(I: LongInt): TbtString;
var
s: tbtstring;
begin
Str(i, s);
IntToStr := s;
end;
//-------------------------------------------------------------------
function FloatToStr(E: Extended): TbtString;
{$ifdef FPC}
begin
result := sysutils.floattostr(e);
end;
{$else}
var
s: tbtstring;
begin
Str(e:0:12, s);
result := s;
end;
{$endif}
function StrToInt(const S: TbtString): LongInt;
var
e: Integer;
Res: LongInt;
begin
Val(string(S), Res, e);
if e <> 0 then
StrToInt := -1
else
StrToInt := Res;
end;
//-------------------------------------------------------------------
function StrToIntDef(const S: TbtString; Def: LongInt): LongInt;
var
e: Integer;
Res: LongInt;
begin
Val(string(S), Res, e);
if e <> 0 then
StrToIntDef := Def
else
StrToIntDef := Res;
end;
//-------------------------------------------------------------------
constructor TPSList.Create;
begin
inherited Create;
FCount := 0;
FCapacity := 16;
{$IFNDEF PS_NOSMARTLIST}
FCheckCount := 0;
{$ENDIF}
GetMem(FData, FCapacity * PointerSize);
end;
function MM(i1,i2: Integer): Integer;
begin
if ((i1 div i2) * i2) < i1 then
mm := (i1 div i2 + 1) * i2
else
mm := (i1 div i2) * i2;
end;
{$IFNDEF PS_NOSMARTLIST}
procedure TPSList.Recreate;
var
NewData: PPointerList;
NewCapacity: Cardinal;
I: Longint;
begin
FCheckCount := 0;
NewCapacity := mm(FCount, FCapacityInc);
if NewCapacity < 64 then NewCapacity := 64;
GetMem(NewData, NewCapacity * PointerSize);
for I := 0 to Longint(FCount) -1 do
begin
NewData^[i] := FData^[I];
end;
FreeMem(FData, FCapacity * PointerSize);
FData := NewData;
FCapacity := NewCapacity;
end;
{$ENDIF}
//-------------------------------------------------------------------
function TPSList.Add(P: Pointer): Longint;
begin
if FCount >= FCapacity then
begin
Inc(FCapacity, FCapacityInc);// := FCount + 1;
ReAllocMem(FData, FCapacity * PointerSize);
end;
FData[FCount] := P; // Instead of SetItem
Result := FCount;
Inc(FCount);
{$IFNDEF PS_NOSMARTLIST}
Inc(FCheckCount);
if FCheckCount > FMaxCheckCount then Recreate;
{$ENDIF}
end;
procedure TPSList.AddBlock(List: PPointerList; Count: Longint);
var
L: Longint;
begin
if Longint(FCount) + Count > Longint(FCapacity) then
begin
Inc(FCapacity, mm(Count, FCapacityInc));
ReAllocMem(FData, FCapacity *PointerSize);
end;
for L := 0 to Count -1 do
begin
FData^[FCount] := List^[L];
Inc(FCount);
end;
{$IFNDEF PS_NOSMARTLIST}
Inc(FCheckCount);
if FCheckCount > FMaxCheckCount then Recreate;
{$ENDIF}
end;
//-------------------------------------------------------------------
procedure TPSList.DeleteLast;
begin
if FCount = 0 then Exit;
Dec(FCount);
{$IFNDEF PS_NOSMARTLIST}
Inc(FCheckCount);
if FCheckCount > FMaxCheckCount then Recreate;
{$ENDIF}
end;
procedure TPSList.Delete(Nr: Cardinal);
begin
if FCount = 0 then Exit;
if Nr < FCount then
begin
Move(FData[Nr + 1], FData[Nr], (FCount - Nr) * PointerSize);
Dec(FCount);
{$IFNDEF PS_NOSMARTLIST}
Inc(FCheckCount);
if FCheckCount > FMaxCheckCount then Recreate;
{$ENDIF}
end;
end;
//-------------------------------------------------------------------
procedure TPSList.Remove(P: Pointer);
var
I: Cardinal;
begin
if FCount = 0 then Exit;
I := 0;
while I < FCount do
begin
if FData[I] = P then
begin
Delete(I);
Exit;
end;
Inc(I);
end;
end;
//-------------------------------------------------------------------
procedure TPSList.Clear;
begin
FCount := 0;
{$IFNDEF PS_NOSMARTLIST}
Recreate;
{$ENDIF}
end;
//-------------------------------------------------------------------
destructor TPSList.Destroy;
begin
FreeMem(FData, FCapacity * PointerSize);
inherited Destroy;
end;
//-------------------------------------------------------------------
procedure TPSList.SetItem(Nr: Cardinal; P: Pointer);
begin
if (FCount = 0) or (Nr >= FCount) then
Exit;
FData[Nr] := P;
end;
//-------------------------------------------------------------------
function TPSList.GetItem(Nr: Cardinal): Pointer; {12}
begin
if Nr < FCount then
GetItem := FData[Nr]
else
GetItem := nil;
end;
//-------------------------------------------------------------------
function TPSStringList.Count: LongInt;
begin
count := List.count;
end;
type pStr = ^TbtString;
//-------------------------------------------------------------------
function TPSStringList.GetItem(Nr: LongInt): TbtString;
var
S: PStr;
begin
s := List.GetItem(Nr);
if s = nil then
Result := ''
else
Result := s^;
end;
//-------------------------------------------------------------------
procedure TPSStringList.SetItem(Nr: LongInt; const s: TbtString);
var
p: PStr;
begin
p := List.GetItem(Nr);
if p = nil
then
Exit;
p^ := s;
end;
//-------------------------------------------------------------------
procedure TPSStringList.Add(const P: TbtString);
var
w: PStr;
begin
new(w);
w^ := p;
List.Add(w);
end;
//-------------------------------------------------------------------
procedure TPSStringList.Delete(NR: LongInt);
var
W: PStr;
begin
W := list.getitem(nr);
if w<>nil then
begin
dispose(w);
end;
list.Delete(Nr);
end;
procedure TPSStringList.Clear;
begin
while List.Count > 0 do Delete(0);
end;