source: branches/2.20_branch/Library/PCharList.pas

Last change on this file was 17, checked in by RBRi, 19 years ago

+ Library

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1Unit PCharList;
2
3Interface
4
5Uses
6 Classes;
7
8Type
9
10 // PCHar list class. It only stores the pointers; it does not copy or
11 // dispose the strings themselves.
12 TPCharList=class
13 protected
14 List: TList;
15 public
16 constructor Create;
17 destructor Destroy; override;
18 // Adds s to the list. Returns index of new item
19 Function Add( S: PChar ): longint;
20 // Returns string at index
21 Function Get( index: longint ): PChar;
22 Procedure Delete( index: longint );
23
24 Procedure Put( index: longint; S: PChar );
25
26 property Strings[ index: longint ]: PChar read Get write Put; default;
27
28 Function Count: longint;
29
30 procedure Clear;
31 procedure Assign( NewText: TPCharList );
32
33 Function IndexOf( SearchText: PChar ): longint;
34 end;
35
36Implementation
37
38Uses
39 SysUtils;
40
41constructor TPCharList.Create;
42Begin
43 List:= TList.Create;
44End;
45
46procedure TPCharList.Clear;
47begin
48 while list.count>0 do
49 Delete( 0 );
50end;
51
52destructor TPCharList.Destroy;
53Begin
54 Clear;
55 List.Destroy
56End;
57
58Function TPCharList.Add( S: PChar ): longint;
59Begin
60 Result:= List.Add( S );
61End;
62
63Function TPCharList.Get( index: longint ): PChar;
64Begin
65 Result:=List[ index ];
66End;
67
68Procedure TPCharList.Delete( index: longint );
69Begin
70 List.Delete( index )
71End;
72
73Procedure TPCharList.Put( index: longint; S: PChar );
74Begin
75 List[ index ]:=S;
76End;
77
78Function TPCharList.Count: longint;
79Begin
80 Result:=List.Count;
81End;
82
83procedure TPCharList.Assign( NewText: TPCharList );
84var
85 i: longint;
86begin
87 Clear;
88 for i:= 0 to NewText.Count - 1 do
89 Add( StrNew( NewText[ i ] ) );
90end;
91
92Function TPCharList.IndexOf( SearchText: PChar ): longint;
93var
94 i: longint;
95begin
96 for i:= 0 to List.Count - 1 do
97 if StrIComp( Strings[ i ], SearchText ) = 0 then
98 begin
99 // found
100 Result:= i;
101 exit
102 end;
103
104 Result:= -1;
105end;
106
107Initialization
108End.
Note: See TracBrowser for help on using the repository browser.